データ構造——スタック——C++実現スタック及びその操作
C++実装スタックの構築と操作:
1:スタックの構造体定義
2:スタックを空にする
3:空のスタックかどうかを判断する
4:インスタック
5:出庫
6:スタック要素全体を表示
親力親為を覚えて、実践的にコードを書く.
Stack.h
Stack.cpp
main.cpp
1:スタックの構造体定義
2:スタックを空にする
3:空のスタックかどうかを判断する
4:インスタック
5:出庫
6:スタック要素全体を表示
親力親為を覚えて、実践的にコードを書く.
Stack.h
#define MAXSIZE 100
typedef int datatype;
typedef struct
{
datatype data[MAXSIZE];
int top; //
} Stack;
//
bool Empty_Stack(Stack &S);
//
bool IsNull(Stack S);
//
bool PushStack(Stack &S,datatype a);
//
bool PopStack(Stack &S);
// ,
datatype Top_element(Stack S);
//
bool show(Stack S);
Stack.cpp
#include "Stack.h"
#include
using std::cin;
using std::cout;
using std::endl;
bool Empty_Stack(Stack &S)
{
S.top = -1;
return true;
}
bool IsNull(Stack S)
{
if (S.top >= 0)
{
return true;
}
return false;
}
//
bool PushStack(Stack &S,datatype a)
{
if (S.top >= MAXSIZE-1) //
{
cout<
main.cpp
/***************************************************************************
* @file main.cpp
* @author MISAYAONE
* @date 17 may 2017
* @remark 17 may 2017
* @theme Stack C++
***************************************************************************/
#include "Stack.h"
#include
using namespace std;
int main(int argc,char** argv)
{
Stack S;
Empty_Stack(S); //
cout<