建立、列印、刪除指定節點、刪除指定字元、查詢指定字元位置、測量鍊錶長度
#include
#include
struct lnode
;void
create
(lnode* l)
//建立鍊錶
scanf_s
("%d"
,&l->data)
;//輸入資料
}void
print
(lnode* l)
//將鍊錶列印
printf
("null\n");
}void
delete
(lnode *l)
//刪除某個節點的元素
lnode* t = new lnode;
t = p;
p->next = p->next->next;
delete
(t);
}void
searchdelete
(lnode*l)
//刪除指定字元
else
t = t->next;
}/*方法二
* lnode *p=l;
* lnode *k=l; k是p的前驅
while(p)
}*/}int
search
(lnode *l)
//查詢指定字元所在位置
q = q->next;
cnt++
;//cnt獲取所在結點位置
}return cnt;
}int
listlength
(lnode *l)
//測量鍊錶長度
printf
("鍊錶長度為:%d\n"
,cnt)
;return cnt;
}int
main()
C語言單鏈表
include include include define error 0 typedef struct lnode lnode,linklist linklist initlist linklist l node next null l node return l int listlength ...
c語言 單鏈表
單鏈表,顧名思義是一種鏈式訪問的資料結構,用一組位址任意的儲存單元存放線性表中的資料元素。鍊錶中的資料是以結點來表示的,每個結點的構成 元素 資料元素的映象 指標 指示後繼元素儲存位置 元素就是儲存資料的儲存單元,指標就是連線每個結點的位址資料。我們在這裡使用c語言實現 h 檔案 pragma on...
C語言單鏈表
學過線性表中的順序表的都知道,順序表裡的資料在物理記憶體上是相鄰的,所以當我們在順序表中想要訪問下乙個元素時可以直接去訪問,就像陣列一樣。但是單鏈表卻不同,單鏈表的資料儲存的位置是動態分配的,也就是說單鏈表的儲存在物理記憶體上不是相鄰的,所以我們就只能通過指標這種方式來把單鏈表串起來,通過指標來訪問...