C語言實現鍊錶的建立 遍歷 插入刪除和逆置

2021-09-10 17:13:32 字數 792 閱讀 7609

#includetypedef struct node

slist;

//鍊錶的建立 需三個輔助指標變數

slist *slistcreate()

return phead;

}//列印鍊錶 需1個輔助指標變數

void slistprint(slist *phead)

}//插入鍊錶 需三個輔助指標變數

void slist_insert(slist *phead,int x,int y)

ppre=pcur;

pcur=pcur->next;

}pm->next=ppre->next;

ppre->next=pm;

return ;

}//刪除乙個節點 相對簡單

void slist_de(slist *phead,int y)

if(pcur==null)

pre->next=pre->next->next;

}//避免野指標問題

void slist_destroy(slist *phead)

}//鍊錶逆置 重點理解

void inverse(slist *phead)

phead->next->next=null;//頭節點變成尾部節點 並使其指標域為null

phead->next=p;

}void main()

注意建立鍊錶的函式可以用二級指標做函式引數直接給phead賦值,也可以採用如上**所寫將堆區建立的首位址通過函式返回值丟出來。

使用C語言實現鍊錶的建立,刪除,查詢,插入

重要的知識點介紹 一 1 status listinsert l linklist l,int i,elemtype e 在第i個位置插入e元素有些函式引數前帶 號 號就是取位址,傳遞變數的指標,使形參得到乙個變數的位址,這時形參指標變數指向實參變數單元,如果我們對帶有 號的變數進行更改,那麼主函式...

C語言實現順序鍊錶的建立和刪除插入元素

include include define len sizeof struct student 順序鍊錶的建立 刪除 插入操作 struct student int n struct student creat else p2 p1 p1 struct student malloc len pri...

建立雙向鍊錶的演算法 C語言實現

雙向鍊錶也叫雙鏈表,是鍊錶的一種,它的每個節點包含兩個指標,分別指向直接後繼和直接前驅 頭節點的前驅指空,尾節點的後繼指空 所以,從雙向鍊錶中的任意乙個非前驅非後繼節點開始,都能很方便地訪問它的前驅和後繼節點。實際上如果熟練掌握了單向鍊錶的基本操作,雙向鍊錶的建立只是每次新建好乙個節點後掛鏈的時候多...