c語言鍊錶的遍歷 刪除 插入等

2021-09-25 00:15:01 字數 727 閱讀 6361

c語言鍊錶的遍歷、刪除、插入等

/*鍊錶的增刪查改*/

#include#include#include//定義學生人數作為全域性變數,方便後面的錄入、遍歷等

int n;

//定義結構體變數

typedef struct phtlist,*plist; //使用typedef,即list等價於struct pht plist等價於 struct pht*

//建立表頭的函式

plist liantou()

//建立鍊錶節點的函式

void jiedian(plist p)

} //鍊錶的遍歷函式(可從頭指標開始進行)

void outputlist(plist p)

}//中間插入節點的函式

void insert(plist p)

p=p->next;

}} //刪除節點函式 (中間節點)

void delete(plist p)

lastone=lastone->next; //lastone下移

p=p->next; //p下移

} if(k=0) //新增k值,用來判斷是否存在該學號

printf("\n該學號不存在");

} /*主函式*/

int main()

順序鍊錶的插入刪除等操作 C語言

順序表的操作 include stdio.h include string.h include stdlib.h 定義表的最大長度 define maxlen 100 定義結點的關鍵字 typedef struct data 定義順序表的結構 typedef struct sltype 初始化順序表...

鍊錶 有序鍊錶(插入刪除遍歷)

插入的節點位置有兩種情況,一是有previous節點,而是沒有previous節點 鏈結點public class link public void displaylink public class sortedlist 插入資料 public void insert long key 說明key是...

鍊錶的建立,插入,刪除,遍歷

includeusing namespace std define ok 1 define error 0 define overflow 2 typedef int status status 是函式返回值型別,其值是函式結果狀態 typedef int elemtype elemtype 為可定...