單鏈表的基礎實現

2021-04-03 02:26:48 字數 916 閱讀 6123

單鏈表的基礎實現3/

23測試環境:tc2.0

#include

#define len sizeof(struct lnode)

#define null 0

typedef int elemtype;

struct lnode

;/*建立乙個帶空頭結點的單鏈表*/

struct lnode *creatlist()

temp->next = null;

return head;

}/*列印出單鏈表*/

void print(struct lnode *head)

}/*銷毀這個線性表*/

void destroylist(struct lnode *head)

}/*在第i個位置前插入新結點*/

void insertlist(struct lnode *head,int i)

if(count>i-1 || !p)

return;

printf("input a number that you want to insert:");

insert = (struct lnode *)malloc(len);

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

insert->next = p->next;

p->next = insert;

}/*刪除第i個結點*/

void deletelist(struct lnode *head,int i)

if(count>i-1 || !p)

return;

temp = p->next;

p->next = temp->next;

free(temp);

}void main()

執行後結果:

實現單鏈表的基礎操作

鍊錶 鍊錶是一種物理儲存結構上非連續 非順序的儲存結構,資料元素的邏輯順序是通過鍊錶中的指標鏈 接次序實現的 下面我們來看看單鏈表的實現 list.h pragma once include include include include 1 無頭單向非迴圈鍊錶增刪查改實現 typedef int ...

單鏈表基礎操作C 實現

最近在複習資料結構,就把單鏈表的基礎操作過了一篇 node.h標頭檔案 templatestruct node node t nval 單鏈錶類檔案 include include node.h include using namespace std templateclass singlelink...

java實現單鏈表,鞏固基礎

package test.written.examination public class singlelinkedlist public node node head,tail public singlelinkedlist public void mp else 新增在頭部 public voi...