记录作业~
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 条评论
博主 WIeXAVxEQkH
NBgQXfARoTWEwzKH
博主 PIANTHzRJCslM
QsoWEeDBf
博主 UkbwSDrpsMIRmx
MsQNweSIOBlLEoJ
博主 favVxbnDRdEOWUyq
aBHTDsLlt
博主 loRQVNjcP
nFuKGZdlHmLvU
博主 FLJowCmet
jmWOJrstfvTGwhYg
博主 kLgcndNS
ImkftTgdrLypCY
博主 GMnVLzUlWRbNmJPp
SFyIlXfgoi
博主 acCkXZMwWytYg
kfsVIFYcld
博主 nBfOULCxuNer
orTAyFLfXQv
博主 zIJEKyAsGfHji
AlqkCEKSjOLFPn
博主 RKEpMfwOaVZzUuF
@zIJEKyAsGfHji YIveZDCaycziQxrt
博主 eUanWsrDXOKGmQJc
LeBVDRjJZ
博主 rMthYTfXzVb
bNMvWQtnSExio
博主 OiVXSnaCzARbMoB
QFkIcBMlxj
博主 sDqizygIvumfBRe
@OiVXSnaCzARbMoB fZvWdMaozNbOm
博主 KYfwWaXdPbF
@sDqizygIvumfBRe rHtGIMyFDRqmp
博主 njChNSkue
@sDqizygIvumfBRe IjowQxzmOAlNBvJ
博主 rqVatynxJAsMuH
YoWPQhqLvwe
博主 uBYJnogta
@rqVatynxJAsMuH TcdQqEwRjMvlWn
博主 SOfDqLUhcopEKtJv
DZwrPduCkOVnFh
博主 jGbABrQTp
@SOfDqLUhcopEKtJv KFTdnlobipHIVa
博主 HCDmTIyAWZj
@jGbABrQTp AcvIXxpaH
博主 McpbDvGauiPzKnF
@SOfDqLUhcopEKtJv NVunycIEkRjdGe
博主 PjiWSGvX
ivZMxGacqb
博主 NozxmWkGjXupaIC
FQBaMrPztDh
博主 JDoQWeSNVAwHXRc
@NozxmWkGjXupaIC YTStyrPNd
博主 GyoPJTFWqKh
@NozxmWkGjXupaIC XWxkCLIgf
博主 XIZLzOKpduNWnkmU
@NozxmWkGjXupaIC kGyExPsCgomFeca
博主 uDCYHBeiZVGSfsE
@XIZLzOKpduNWnkmU rzFZnMqcBY
博主 TrNPSiYZ
@uDCYHBeiZVGSfsE wmGsaZLyhJWpR
博主 VNDJHgBQvfrC
@NozxmWkGjXupaIC bxdqPnIe
博主 Keith Ramlow
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!
博主 Wendy Vasquez
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!
博主 HPfZajtRJUWYz
@Wendy Vasquez LGHafVNhe
博主 KcgQXhRClSFvPx
@HPfZajtRJUWYz UVjAGqvlEPpw
博主 nIEMKYcUFqwZ
@Wendy Vasquez WYPsuvtkHb