C 單鏈表的實現

2021-07-07 01:15:47 字數 1331 閱讀 3477

#include

#include

#include

#include

using namespace std;

typedef struct student

node;

node *create() //建立單鏈表

else cycle = 0;

}head  = head->next;

p ->next = null;

//coutreturn head;

}int length(node *head) //求單鏈表的長度

return n;

}void print(node *head) //列印鍊錶

coutp1 = head;

while(num != p1->data && p1->next != null)

if(num == p1->data)

else

}else

cout}void insert(node *head, int num)//在鍊錶中按大小順序插入某節點

if(p0->data <= p1->data)

else

}else

}node *sort(node *head)//單鏈表的排序

p1 = p1->next;}}

return head;

}node *reverse(node *head)

head->next = null;

head = p1;

}void removehead(node *head) //刪除頭節點

void searchmid(node *head)

couthead = create();

int l,de_num,in_num;

l = length(head);

cout<<"鍊錶長度:"//head = del(head,2);

cout<<"請輸入需要刪除的值:">de_num;

del(head,de_num);

l = length(head);

cout<<"鍊錶長度:"cout<<"請輸入需要插入的值:">in_num;

insert(head,in_num);

l = length(head);

cout<<"鍊錶長度:"head = sort(head);

cout<<"排序後的結果:"head = reverse(head);

cout<<"逆置後的結果:"removehead(head);

cout<<"刪除頭結點後的結果:"cout<<"鍊錶中間值是:"return 0;

}

單鏈表的c 實現

node類標頭檔案 ifndef node h define node h include include using namespace std class node endif node類cpp include node.h using namespace std 過載 運算子 ostream ...

單鏈表的C 實現

include using namespace std struct node class list void insertlist int adata,int bdata void deletelist int adata void outputlist node gethead void lis...

單鏈表的實現(C )

個人風格,我覺得最應該把總結放到最前面寫,因為查閱相關部落格的人都是了解了一些背景知識的,他們可能需要的就是關鍵的點睛之筆。typedef struct node linknode,linklist linknode 代表的是乙個node,而 linklist 代表的則是指向這個 node 的指標,...