生活随笔
收集整理的這篇文章主要介紹了
链栈的操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
鏈棧的定義
#include <iostream>
using namespace std
;
typedef struct _QNode
{int data
;struct _QNode *next
;
}StNode
;
鏈棧的操作
初始化
bool initStack(StNode
* &st
)
{st
= new StNode
;if(!st
) return false;st
->next
= NULL;return true;
}
判斷棧空
bool isEmpty(StNode
*st
)
{if(st
->next
== NULL)return true;elsereturn false;
}
入棧
bool pushStack(StNode
* &st
, int e
)
{StNode
*node
= new StNode
;if(!node
) return false;node
->data
= e
;node
->next
= st
->next
;st
->next
= node
;return true;
}
出棧
bool popStack(StNode
* &st
, int &e
)
{if(!(st
->next
)) return false; StNode
*p
;p
= st
->next
;e
= p
->data
;st
->next
= p
->next
;delete p
;return true;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的链栈的操作的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。