您好,登錄后才能下訂單哦!
算法示意圖:
#include <iostream> using namespace std; struct DATA { int id; char name[20]; }; struct info { DATA data; info * pNext; }; //頭節(jié)點 info * g_Head = NULL; void CreateList() { //創(chuàng)建頭節(jié)點 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; }
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。