#pragma once
#include<stdio.h>
#include<stdlib.h>
typedef int SLTDateType;
typedef struct SListNode {
SLTDateType data;
struct SListNode* next;
}SLTNode;
void SListPrint(SLTNode* phead);//create一个头节点
void SListPushBack(SLTNode** phead, SLTDateType x);
#include"SList.h"
void SListPrint(SLTNode* phead) {
SLTNode* cur = phead;
while (cur != NULL) {
printf("%d->", cur->data);
cur = cur -> next;
}
}
void SListPushBack(SLTNode** phead, SLTDateType x) {
/*SLTNode* tail = phead;
while (tail->next != NULL) {
tail = tail->next;
}*/
SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
newnode->data = x;
newnode->next = NULL;
if (*phead == NULL) {
*phead = newnode;
}
else {
SLTNode* tail = *phead;
while (tail->next != NULL) {
tail = tail->next;
}
tail->next = newnode;
}
}
#include"SList.h"
void Test() {
SLTNode* plist = NULL;//plist,头指针
SListPushBack(&plist,1);
SListPushBack(&plist, 2);
SListPushBack(&plist, 3);
SListPushBack(&plist, 4);
SListPrint(plist);
}
int main() {
Test();
return 0;
}