完整的鍊錶操作(定義 建立 插入 刪除 輸出)

2021-07-05 13:56:47 字數 687 閱讀 9241

#include

#include

struct student

;int icount; //全域性變數表示鍊錶長度

struct student* create()

else

pnew=(struct student*)malloc(sizeof(struct student)); //再次分配結點記憶體空間

scanf("%s",&pnew->cname);

scanf("%s",&pnew->inumber);

}free(pnew);

return phead;

} void print(struct student* phead) }

struct student* insert(struct student* phead)

void delete(struct student* phead,int iindex) //phead表示頭結點,iindex表示要刪除的結點的下標

ppre->pnext=ptemp->pnext; //連線刪除結點兩邊的結點

free(ptemp); //釋放掉要刪除結點的記憶體空間

icount--; //減少鍊錶中的元素個數

} int main()

鍊錶建立 插入 刪除

這兩天,拼命理解鍊錶,儘管現在理解還是不夠,但終於把長久以來一直折磨我的鍊錶用c 打出來了。還是有點小小的成就感。以下是 包括鍊錶建立 頭插法和尾插法 插入乙個位置的鍊錶 刪除乙個位置的鍊錶以及整個鍊錶的刪除。define null 0 include using namespace std int...

鍊錶的建立 刪除 插入

1.鍊錶的建立 需要乙個頭指標 結點指標 尾指標即可。這裡值得注意的是,建立的過程頭指標是不能變的,而每次插入乙個節點,尾指標都要後移乙個節點 一開始把尾指標指向頭指標 如建立含有n個結點的鍊錶如下 node create else pend next null ps new node delete...

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

定義結點 結構體型別 定義指向結點的指標變數 必須有頭指標 head,p1,p2 新建結點 malloc函式開闢記憶體 指向如果是第乙個結點,則讓頭指標head指向該結點 若不是第乙個結點,則讓上乙個結點的指標變數指向該結點 最後讓尾結點的指標變數指向null 如 list pre pre next...