记录作业~
SList.h
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include<assert.h>
typedef int SLTDateType;
typedef struct SListNode
{
SLTDateType data;
struct SListNode* next;
}SLTNode;
void SListPrint(SLTNode* phead);
void SListPushBack(SLTNode** pphead, SLTDateType x);
void SListPushFront(SLTNode** pphead, SLTDateType x);
void SListPopBack(SLTNode** pphead);
void SListPopFront(SLTNode** pphead);
SLTNode* SListFind(SLTNode* phead, SLTDateType x);
void SListInsert(SLTNode** pphead, SLTNode* pos, SLTDateType x);
void SListErase(SLTNode** pphead, SLTNode* pos);
void SListDestroy(SLTNode** pphead);
SList.c
#include "SList.h"
void SListPrint(SLTNode* phead)
{
SLTNode* cur = phead;
while (cur != NULL)
{
printf("%d->", cur->data);
cur = cur->next;
}
printf("NULL\n");
}
SLTNode* SListFind(SLTNode* phead, SLTDateType x)
{
SLTNode* cur = phead;
while (cur)
{
if (cur->data == x) {
return cur;
}
else {
cur = cur->next;
}
}
return NULL;
}
SLTDateType* BuyListNode(SLTDateType x)
{
SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
newnode->data = x;
newnode->next = NULL;
return newnode;
}
void SListPushBack(SLTNode** pphead, SLTDateType x)
{
SLTNode* newnode = BuyListNode(x);
if (*pphead == NULL){
*pphead = newnode;
}
else{
SLTNode* tail = *pphead;
while (tail->next != NULL)
{
tail = tail->next;
}
tail->next = newnode;
}
}
void SListPushFront(SLTNode** pphead, SLTDateType x)
{
SLTNode* newnode = BuyListNode(x);
newnode->next = *pphead;
*pphead = newnode;
}
void SListPopBack(SLTNode** pphead)
{
assert(*pphead != NULL);
if ((*pphead)->next == NULL) {
free(*pphead);
*pphead = NULL;
}
else {
SLTNode* tail = *pphead;
SLTNode* prev = NULL;
while (tail->next)
{
prev = tail;
tail = tail->next;
}
free(tail);
tail = NULL;
prev->next = NULL;
}
}
void SListPopFront(SLTNode** pphead)
{
assert(*pphead != NULL);
SLTNode* next = (*pphead)->next;
free(*pphead);
*pphead = next;
}
void SListInsert(SLTNode** pphead, SLTNode* pos, SLTDateType x)
{
SLTNode* newnode = BuyListNode(x);
if (*pphead == pos) {
newnode->next = *pphead;
*pphead = newnode;
}
else {
SLTNode* posPrev = *pphead;
while (posPrev->next != pos)
{
posPrev = posPrev->next;
}
posPrev->next = newnode;
newnode->next = pos;
}
}
void SListErase(SLTNode** pphead, SLTNode* pos)
{
if (*pphead == pos) {
SListPopFront(pphead);
}
else {
SLTNode* prev = *pphead;
while (prev->next != pos)
{
prev = prev->next;
}
prev->next = pos->next;
free(pos);
}
}
void SListDestroy(SLTNode** pphead)
{
assert(pphead);
SLTNode* cur = *pphead;
while (cur)
{
SLTNode* next = cur->next;
free(cur);
cur = next;
}
*pphead = NULL;
}
Comments | 58 条评论
NBgQXfARoTWEwzKH
QsoWEeDBf
MsQNweSIOBlLEoJ
aBHTDsLlt
nFuKGZdlHmLvU
jmWOJrstfvTGwhYg
ImkftTgdrLypCY
SFyIlXfgoi
kfsVIFYcld
orTAyFLfXQv
AlqkCEKSjOLFPn
@zIJEKyAsGfHji YIveZDCaycziQxrt
LeBVDRjJZ
bNMvWQtnSExio
QFkIcBMlxj
@OiVXSnaCzARbMoB fZvWdMaozNbOm
@sDqizygIvumfBRe rHtGIMyFDRqmp
@sDqizygIvumfBRe IjowQxzmOAlNBvJ
YoWPQhqLvwe
@rqVatynxJAsMuH TcdQqEwRjMvlWn
DZwrPduCkOVnFh
@SOfDqLUhcopEKtJv KFTdnlobipHIVa
@jGbABrQTp AcvIXxpaH
@SOfDqLUhcopEKtJv NVunycIEkRjdGe
ivZMxGacqb
FQBaMrPztDh
@NozxmWkGjXupaIC YTStyrPNd
@NozxmWkGjXupaIC XWxkCLIgf
@NozxmWkGjXupaIC kGyExPsCgomFeca
@XIZLzOKpduNWnkmU rzFZnMqcBY
@uDCYHBeiZVGSfsE wmGsaZLyhJWpR
@NozxmWkGjXupaIC bxdqPnIe
Woah! I’m really loving the template/theme of this site.
It’s simple, yet effective. A lot of times it’s hard to get that
"perfect balance" between user friendliness and appearance.
I must say that you’ve done a fantastic job with this.
In addition, the blog loads super quick for me on Safari.
Superb Blog!
My brother recommended I might like this website. He was once totally right.
This publish actually made my day. You cann’t believe
simply how much time I had spent for this information! Thank you!
@Wendy Vasquez LGHafVNhe
@HPfZajtRJUWYz UVjAGqvlEPpw
@Wendy Vasquez WYPsuvtkHb