/*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 />}