鍊錶逆序:
1//鍊錶操作:該示例中,煉表頭節點不儲存資料2//
1.鍊錶建立3//
2.鍊錶遍歷,列印4//
3.鍊錶節點長度統計5//
4.鍊錶刪除6//
5.插入節點7//
6.刪除節點8//
7.拼接鍊錶9//
8.倒序
10//
9.排序
1112 #include 13 #include 14 #include
15//
declaration of node
16//
乙個鍊錶節點定義node,鍊錶節點指標定義pnode
17 typedef struct
node
18node,*pnode;
22//
operations of list
23 pnode list_creat(void
);24
void
list_free(pnode phead);
25void
list_display(pnode phead);
26int
list_len(pnode phead);
27void list_delete(pnode phead, int
num);
28void list_insert(pnode phead, int
num);
29pnode list_splice(pnode phead1, pnode phead2);
30void
list_reverse(pnode phead);
31void
list_sort_bubble(pnode phead);
3233
intmain()
3454
//1.根據輸入建立鍊錶
55 pnode list_creat(void)56
75return
phead;76}
77//
刪除鍊錶
78void
list_free(pnode phead)
7988 printf("
current list deleted!!!\r\n");
89}90//
列印鍊錶
91void
list_display(pnode phead)
92100
}101
//遍歷,統計長度
102int
list_len(pnode phead)
103111
return
len;
112}
113114
//指定位置插入節點
115void list_insert(pnode phead,int
num)
116//
i==num
124 pnode pnew = (pnode)malloc(sizeof
(node));
125 printf("
please input value of the current node:\r\n");
126 scanf_s("
%d", &value);
127 pnew->value =value;
128 pnew->pnext = p->pnext;
129 p->pnext =pnew;
130}
131//
指定位置刪除節點
132void list_delete(pnode phead,int
num)
133//
i==num-1
142 pb = p->pnext->pnext;
143 free(p->pnext);
144 p->pnext =pb;
145}
146//
拼接鍊錶
147pnode list_splice(pnode phead1, pnode phead2)
148154 p->pnext = phead2->pnext;
155free(phead2);
156return
phead1;
157}
158void
list_reverse(pnode phead)
159172 phead->pnext =pa;
173}
174//
排序175
void
list_sort_bubble(pnode phead)
176200
else
201205
}206 pend = p;//
排序終結點前移乙個節點
207}
208 }
單向鍊錶demo
class stunode val pno int,val pname string 說明 只是demo用於理解,有很多漏洞,具體根據應用場景解決 class singlelinklist tmp tmp.next 此時tmp就是尾節點 tmp.next stunode 遍歷 def list un...
C 簡單的通用鍊錶Demo
很早以前寫的乙個例子,簡單的模仿stl實現乙個鍊錶。我想對於想使用c 寫乙個簡單鍊錶的初學者有幫助 簡單的鍊錶c 實現 aothor 殷洪 date 2006 06 18 email 47406310 qq.com include stdafx.h include include include u...
有序鍊錶合併兩個002
21將兩個公升序鍊錶合併為乙個新的 公升序 鍊錶並返回。新煉表是通過拼接給定的兩個鍊錶的所有節點組成的。題目鏈結 示例 輸入 1 2 4,1 3 4 輸出 1 1 2 3 4 4 鍊錶,有序,合併 1 雙指標迭代 構造乙個新的,然後乙個乙個的比較,2 遞迴 遞迴3要素 1 終止條件 當其中任乙個遍歷...