#include"linkqueue.h"
struct Student { struct QueueNode node; char name[64]; int age; };
int main(int argc, char *argv[]) { LinkQueue queue = InitLinkQueue();
struct Student p1 = { NULL, "aaa", 10 }; struct Student p2 = { NULL, "bbb", 20 }; struct Student p3 = { NULL, "ccc", 30 }; struct Student p4 = { NULL, "ddd", 40 }; struct Student p5 = { NULL, "eee", 50 }; struct Student p6 = { NULL, "fff", 60 };
PushLinkQueue(queue, &p1); PushLinkQueue(queue, &p2); PushLinkQueue(queue, &p3); PushLinkQueue(queue, &p4); PushLinkQueue(queue, &p5); PushLinkQueue(queue, &p6);
struct Student *pBack = (struct Student *)BackLinkQueue(queue); printf("队尾元素: %s %d\n", pBack->name, pBack->age);
while (SizeLinkQueue(queue) > 0) { struct Student *person = (struct Student *)FrontLinkQueue(queue); printf("姓名: %s 年龄: %d \n", person->name, person->age); PopLinkQueue(queue); } DestroyLinkQueue(queue);
system("pause"); return 0; }
|