鏈表實現檔案C語言

來源:互聯網
上載者:User

/*linked_list.c -- 鏈表實現檔案*/<br />#include <stdio.h><br />#include <stdlib.h><br />#include "linked_list.h"</p><p>/*局部函式宣告*/</p><p>static Linked_List_Node * Make_Node (const Linked_List_Item li1, const Linked_List_Item li2) ;</p><p>/*介面函數定義*/</p><p>int Initialize_L (List * const pli)<br />{<br />*pli = NULL ;</p><p>return 1 ;<br />}</p><p>int IsEmpty_L (const List * const pli)<br />{<br />return NULL == *pli ;<br />}</p><p>int Insert_L (List * const pli, const Linked_List_Item li1, const Linked_List_Item li2)<br />{<br />Linked_List_Node * new_node ;</p><p>new_node = Make_Node (li1, li2) ;<br />if (NULL == new_node)<br />return 0 ;<br />new_node -> next = *pli ;<br />*pli = new_node ;</p><p>return 1 ;<br />}</p><p>int Find_L (const List * const pli, const Linked_List_Item li1, const Linked_List_Item li2)<br />{<br />Linked_List_Node * scan ;</p><p>scan = *pli ;<br />while (scan)<br />{<br />if (li1 == scan -> v && li2 == scan -> w)<br />return 1 ;<br />else<br />scan = scan -> next ;<br />}</p><p>return 0 ;<br />}</p><p>int Delete_L (List * const pli, const Linked_List_Item li1, const Linked_List_Item li2)<br />{<br />Linked_List_Node * scan, * temp ;</p><p>if (IsEmpty_L (pli))<br />return 0 ;<br />scan = *pli ;<br />/*There is nly one node in the list and hit the target*/<br />if (NULL == scan -> next && li1 == scan -> v && li2 == scan -> w)<br />{<br />free (scan) ;<br />*pli = NULL ;<br />return 1 ;<br />}<br />while (scan -> next && scan -> next -> v != li1 && scan -> next -> w != li2)<br />scan = scan -> next ;<br />if (scan -> next)<br />{<br />temp = scan -> next ;<br />scan -> next = temp -> next ;<br />free (temp) ;<br />return 1 ;<br />}<br />else<br />return 0 ;<br />}</p><p>void Traversal_L (const List * const pli, void (* pfun) (const Linked_List_Node * const pln))<br />{<br />Linked_List_Node * scan ;</p><p>scan = *pli ;<br />while (scan)<br />{<br />(* pfun) (scan) ;<br />scan = scan -> next ;<br />}<br />}</p><p>void Release_L (const List * const pli)<br />{<br />Linked_List_Node * scan, * temp ;</p><p>scan = *pli ;<br />while (scan)<br />{<br />temp = scan ;<br />scan = scan -> next ;<br />free (temp) ;<br />}</p><p>}</p><p>/*局部函數定義*/</p><p>static Linked_List_Node * Make_Node (const Linked_List_Item li1, const Linked_List_Item li2)<br />{<br />Linked_List_Node * new_node ;</p><p>new_node = (Linked_List_Node *) malloc (sizeof (Linked_List_Node)) ;<br />if (NULL == new_node)<br />return NULL ;<br />new_node -> v = li1 ;<br />new_node -> w = li2 ;</p><p>return new_node ;<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.