分类:
版权声明:本文为博主原创文章,未经博主允许不得转载。
- //实现调用和功能实现分开 双向链表
- #include "stdafx.h"
- void BuildData()
- {
- Person data;
- while(1){
- scanf("%d %s %s",&data.iId,
- data.szName,data.szMajor);
- if(data.iId<1)
- break;
- PushBack(&data);
- }
- }
- void PrintData()
- {
- Person data;
- while(PopFront(&data)){
- printf("id:%d,name:%s,major:%s\n",
- data.iId,data.szName,data.szMajor);
- }
- }
- int main()
- {
- BuildData();
- PrintData();
- return 0;
- }
- //stack.h
- #if !defined __STACK_H__
- #define __STACK_H__
- #include "stdafx.h"
- struct Person
- {
- int iId;
- char szName[16];
- char szMajor[16];
- };
- struct Node
- {
- Person date;
- Node *pBack;
- Node *pNext;
- };
- void PushBack(const Person *pDate);
- bool PopFront(Person *pDate);
- #endif
- //stack.cpp
- #include "stdafx.h"
- static Node *g_pHead=NULL;
- static Node *g_taill=NULL;
- void PushBack(const Person *pDate)
- {
- Node *pNode=(Node*)malloc(sizeof(Node));
- pNode->date=*pDate;
- pNode->pNext=g_pHead;
- g_pHead=pNode;
- }
- bool PopFront(Person *pDate)
- {
- Node *pDelete=g_pHead;
- if(g_pHead==NULL)
- return false;
- *pDate=g_pHead->date;
- g_pHead=g_pHead->pNext;
- free(pDelete);
- return true;
- }