C語言靜態鍊錶(指定節點的前後插入新節點與刪除)

2021-10-17 08:28:02 字數 3316 閱讀 9057

靜態鍊錶相對動態鍊錶,(基於你指標和結構體,記憶體有清晰的認識的情況下)比較簡單,下面是小生的練習**,提供給大家。

#include #include struct test

;void prinlink(struct test *head)

}int main()

; struct test t2=;

struct test t8=;

struct test t3=;

struct test t4=;

t1.next = &t2;

t2.next = &t8;

t8.next = &t3;

t3.next = &t4;

prinlink(&t1);

system("pause");

return 0;

}

#include #include struct test

;void prinlink(struct test *head)

putchar('\n');

}int chazhao(struct test *head) //查詢節點個數

return cnt;

}int chashu(struct test *head,int data) //查詢有沒有這個點

p = p->next;

}return 0;

}int main()

; struct test t2=;

struct test t3=;

struct test t4=;

struct test t5=;

t1.next = &t2;

t2.next = &t3;

t3.next = &t4;

t4.next = &t5;

prinlink(&t1);

int ret;

ret = chazhao(&t1);

printf("ret = %d",ret);

putchar('\n');

int pon;

pon = chashu(&t1,3);

if(pon == 1)else

putchar('\n');

pon = chashu(&t1,9);

if(pon == 1)else

system("pause");

return 0;

}

#include #include struct test 

;void prinlink(struct test *head)

putchar('\n');

}int houm(struct test *head,int data,struct test *new)

p = p->next;

}return 0;

}int main()

; struct test t2 = ;

struct test t3 = ;

struct test t4 = ;

struct test t5 = ;

struct test t6 = ;

t1.next = &t2;

t2.next = &t3;

t3.next = &t4;

t4.next = &t5;

prinlink(&t1);

putchar('\n');

houm(&t1,3,&t6);

prinlink(&t1);

system("pause");

return 0;

}

#include #include struct test

;struct test *qianm(struct test *head,int data,struct test *new)

while(p->next != null)

p = p->next;

}return 0;

}void prinlink(struct test *head)

}int main()

; struct test t2 = ;

struct test t3 = ;

struct test t4 = ;

struct test t5 = ;

t1.next = &t2;

t2.next = &t3;

t3.next = &t4;

t4.next = &t5;

head = &t1;

struct test new = ;

head = qianm(head,5,&new);

prinlink(head);

putchar('\n');

struct test new2 = ;

head = qianm(head,999,&new2);

prinlink(head);

system("pause");

return 0;

}

#include #include struct test

;void prinlink(struct test *head)

}struct test *shanchu(struct test *head,int data)

while(p->next != null)

p = p->next;

}return 0;

}int main()

; struct test t2 = ;

struct test t3 = ;

struct test t4 = ;

struct test t5 = ;

t1.next = &t2;

t2.next = &t3;

t3.next = &t4;

t4.next = &t5;

head = &t1;

prinlink(head);

putchar('\n');

head = shanchu(head,3);

prinlink(head);

putchar('\n');

system("pause");

return 0;

}

函式名起的不是很好,見諒o( ̄▽ ̄)d 。

**裡面有一些小演算法,看不懂可以多看幾遍o( ̄▽ ̄)d 。

鍊錶刪除指定位置節點 C語言

這裡有個小技巧,容易錯誤。傳入的是個雙重指標 st datanode phead,因為刪除在首節點的位置時候,煉表頭的位置會發生改變,指向新的節點,所以需要傳入雙重指標,以便接收修改的新的煉表頭的位置 實現 st datanode removelistnode st datanode phead,i...

靜態鍊錶實現(C語言)

對於線性鍊錶,也可用一維陣列來進行描述。這種描述方法便於在沒有指標型別的高階程式語言中使用鍊錶結構。先上 include define maxsize 7 typedef struct slinklist maxsize 初始化靜態鍊錶 void list init slinklist list 插...

靜態鍊錶 C語言描述

靜態鍊錶 1.下標為0的游標存放最後存放資料節點的游標,即是第乙個沒有存放元素 備用鍊錶 的下標 2.最後乙個的節點存放第乙個由數值得下標 3.第乙個和最後乙個都不存放資料 即是備用鍊錶的第乙個的下標 4.最後乙個儲存資料的節點的游標為0 靜態鍊錶主要是根據游標來遍歷,以前沒有指標用的思想 假如我要...