棧實現檔案C語言

來源:互聯網
上載者:User

/*Stack_ADT.c -- 棧模型實現檔案*/<br />#include <stdio.h><br />#include <stdlib.h><br />#include "Stack_ADT.h"</p><p>/*局部函式宣告*/</p><p>static Stack_Node * Make_Node (const Name * const panme) ;</p><p>/*介面函數定義*/</p><p>int InitializeStack (Stack * const pstack)<br />{<br />*pstack = (Stack_Node *) malloc (sizeof (Stack_Node)) ;<br />if (NULL == *pstack)<br />return 0 ;<br />else<br />{<br />*pstack = NULL ;<br />return 1 ;<br />}<br />}</p><p>int StackIsEmpty (const Stack * const pstack)<br />{<br />return NULL == *pstack ;<br />}</p><p>int Push (Stack * const pstack, const Name * const pname)<br />{<br />Stack_Node * new_node ;</p><p>new_node = Make_Node (pname) ;<br />if (new_node)<br />{<br />new_node -> next = *pstack ;<br />*pstack = new_node ;<br />return 1 ;<br />}<br />else<br />return 0 ;<br />}</p><p>int Pop (Stack * const pstack, Name * const pname)<br />{<br />Stack_Node * temp ;</p><p>if (StackIsEmpty (pstack))<br />return 0 ;<br />else<br />{<br />*pname = (*pstack) -> name ;<br />temp = *pstack ;<br />*pstack = (*pstack) -> next ;<br />free (temp) ;<br />return 1 ;<br />}<br />}</p><p>void Traversal (const Stack * const pstack, void (* pfun) (const Stack_Node * const stack_node))<br />{<br />Stack_Node * scan = *pstack ;</p><p>while (scan)<br />{<br />(* pfun) (scan) ;<br />scan = scan -> next ;<br />}<br />}</p><p>void ReleaseStack (const Stack * const pstack)<br />{<br />Stack_Node * temp, * scan = *pstack ;</p><p>while (scan)<br />{<br />temp = scan ;<br />scan = scan -> next ;<br />free (temp) ;<br />}<br />}</p><p>/*局部函數定義*/</p><p>static Stack_Node * Make_Node (const Name * const pname)<br />{<br />Stack_Node * new_node ;</p><p>new_node = (Stack_Node *) malloc (sizeof (Stack_Node)) ;<br />if (new_node)<br />{<br />new_node -> name = *pname ;<br />}</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.