C語言寫的鍊錶

2021-07-25 17:45:31 字數 1063 閱讀 6050

//怎麼會說c++的鍊錶和c語言不一樣呢?

// //好吧,我再寫一遍c語言的單鏈表。

#include"stdio.h"

#include"stdlib.h"

typedef struct lianbiao

lianbiao;

lianbiao * chuangjian()//建立頭節點

void xiaohui(lianbiao *tou)//銷毀全部節點

free(p);

}//刪除第pos個節點。

void xiaohuipos(lianbiao *tou,int pos)//銷毀第 pos 個節點。頭節點為 第 0 個。

lianbiao *temp1=p->next;

p->next=temp1->next;

free(temp1);

}void zengjia_tou(lianbiao * tou)//在頭增加節點。

void zengjia_wei(lianbiao * tou)//尾部增加節點

lianbiao *newdata=(lianbiao *)malloc(sizeof(lianbiao));

printf("輸入鍊錶尾部增加的資料:_______\b\b\b\b\b");

scanf("%d",&newdata->data);

newdata->next=null;

p->next=newdata;

printf("\n");

}int chazhao(lianbiao *tou,int data)//查詢資料,返回位置。沒找到返回 -1 .

p=p->next;

} return pos;

} void jianli(lianbiao *tou)//建立鍊錶

printf("\n輸入完畢\n");

}void dayin(lianbiao *tou)//列印鍊錶

printf("end\n");

}int main(int argc,char *argv)



c語言 鍊錶 C語言鍊錶例項 玩轉鍊錶

下圖為最一簡單鍊錶的示意圖 第 0 個結點稱為頭結點,它存放有第乙個結點的首位址,它沒有資料,只是乙個指標變數。以下的每個結點都分為兩個域,乙個是資料域,存放各種實際的資料,如學號 num,姓名 name,性別 和成績 score 等。另乙個域為指標域,存放下一結點的首位址。鍊錶中的每乙個結點都是同...

c語言鍊錶 鍊錶

在儲存一大波數的時候,我們通常使用陣列,但有時候陣列顯得不夠靈活,比如有一串已經從小到大排序好的數 2 3 5 8 9 10 18 26 32 現在需要往這串數中插入6使其得到的新序列仍符合從小到大排列。如果我們使用陣列來實現這一操作,則需要將8和8後面的數字都依次往後挪一位,如果你覺得這幾個數不算...

c語言 鍊錶 C語言之鍊錶入門

鍊錶三要素 1 頭指標 head 是用來說明鍊錶開始了,頭指標就代表鍊錶本身 所以以後要訪問鍊錶,就要訪問頭指標 2 結點 node 鍊錶中每乙個結構體變數 3 尾指標 用來說明鍊錶的結束 它是乙個空指標,null include includetypedef struct stud 定義了乙個結構...