2 双向链表 PushBack/PopFront
//实现调用和功能实现分开 双向链表
#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;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
