C語言編寫簡單的單鏈表(增刪改查)

2021-09-29 15:59:58 字數 1441 閱讀 9933

純自己寫的,就是想試一下自己對指標、鍊錶內容的理解程度,沒有經過大量測試,只自己小小的測試了一下。

#include#include#includestruct node

;struct node *creat();

void show(struct node *first);

bool insert(struct node * first,int postion,int value);

bool delete(struct node * first,int postion);

bool updata(struct node * first,int postion,int value);

int select(struct node * first,int value);

int main()

/*******建立鍊錶,-1表示結束*******/

struct node *creat()

if(first==null)

else

scanf("%d",&value);

if(value == -1)

p->value=value;

}return first;

}/*******查詢數值為value的節點,返回是第幾個節點*******/

int select(struct node * first,int value)

i++;

p=p->next;

}return i;

}/*******查詢數值為value的節點,返回是第幾個節點*******/

bool insert(struct node * first,int postion,int value)

struct node *e = (struct node *)malloc(sizeof(struct node));

e->value=value;

e->next=p->next;

p->next=e;

return true;

}/*******刪除某個節點*******/

bool delete(struct node * first,int postion)

if(p->next==null)

else

free(p);

return true;

}/*******更新位置為postion的節點資料為value*******/

bool updata(struct node * first,int postion,int value)

p->value=value;

return true;

}/*******遍歷鍊錶*******/

void show(struct node *first)

}

C語言單鏈表 增 刪 改 查

鍊錶是一種常見的基礎資料結構,結構體指標在這裡得到了充分的利用。鍊錶可以動態的進行儲存分配,也就是說,鍊錶是乙個功能極為強大的陣列,他可以在節點中定義多種資料型別,還可以根據需要隨意增添,刪除,插入節點。鍊錶都有乙個頭指標,一般以head來表示,存放的是乙個位址。鍊錶中的節點分為兩類,頭結點和一般節...

c語言 單鏈表的增刪改查(簡單版)

在學了鍊錶之後,自己也能寫出乙個簡單的鍊錶結構,這裡就將自己的 分享一下。如果發現有不足之處,歡迎指出。typedef struct dnode snode,ptr 這裡返回的是head,ptr initlink 初始化鍊錶並插入元素 向後插入 p head head head next free ...

單鏈表的簡單增刪改查

package com.mjw.linkedlist public class singlelinkedlistdemo 4.定義singlelinkedlist來管理英雄結點 class singlelinkedlist if temp.next.no heronode.no else if te...