效果展示
测试代码
#include <stdio.h>
#include <stdlib.h>
#include "linkStack.h"
#include <conio.h>
#include <string.h>
typedef struct PERSON
{
LinkNode *node;
char name[64];
int age;
}Person;
void test01()
{
//创建链表
LinkStack *list=InitStack();
//创建数据
Person p1,p2,p3,p4,p5;
strcpy(p1.name,"ggj");
strcpy(p2.name,"zqx");
strcpy(p3.name,"wjy");
strcpy(p4.name,"lx");
strcpy(p5.name,"wjy");
p1.age=22;
p2.age=23;
p3.age=21;
p4.age=21;
p5.age=21;
//将结点插入链表
Push_SeqStack(list,(LinkNode*)&p1);
Push_SeqStack(list,(LinkNode*)&p2);
Push_SeqStack(list,(LinkNode*)&p3);
Push_SeqStack(list,(LinkNode*)&p4);
int size=Size_SeqStack(list);
printf("链表长度为%d\n",size);
while(size>0)
{
//取出链表元素
Person *p=(Person *)TopStack(list);
Pop_SeqStack(list);
printf("name:%s age:%d\n",p->name,p->age);
}
FreeSpace(list);
system("pause");
}
int main()
{
test01();
getch();
return 0;
}