算法示意图:
#include <iostream> using namespace std; struct DATA { int id; char name[20]; }; struct info { DATA data; info * pNext; }; //头节点 info * g_Head = NULL; void CreateList() { //创建头节点 info * pHead = new info; if(pHead) { pHead->data.id = NULL; memset(pHead->data.name,0,10); pHead->pNext = NULL; g_Head = pHead; } } void Add(int id,char * str) { info * pData = new info; pData->data.id = id; strcpy(pData->data.name,str); pData->pNext = NULL; info * p = g_Head,*p1; while(p) { p1 = p; p = p->pNext; } p1->pNext = pData; } void print() { info * p = g_Head; while(p) { cout << p->data.id << " " << p->data.name << endl; p = p->pNext; } } int main(int argc, char* argv[]) { CreateList(); Add(1,"李大"); Add(2,"王五"); Add(3,"罗博特"); print(); getchar(); return 0; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。