C++ 简单实现压栈出栈 -电脑资料

时间:2019-06-05 05:16:27
染雾
分享
WORD下载 PDF下载 投诉

/**********************************************************************   * Copyright (c)2015,WK Studios * Filename:  stack.h   * Compiler: GCC,VS,VC6.0  win32   * Author:WK   * Time: 2015 3 29 ************************************************************************/ #include<iostream>using namespace std;const int SIZE=10;class Stack{private:    int stck[SIZE];//数组用于存放栈中数据    int tos;       //栈顶位置(数组的下标)public:	Stack();	void push(int ch); //函数声明向栈中中压入数据fuction    int  pop();       //声明从堆栈中弹出数据fuction	void ShowStack(); //声明显示堆栈数据function};</iostream>

/**********************************************************************   * Copyright (c)2015,WK Studios * Filename:  stack.cpp  * Compiler: GCC,VS,VC6.0  win32   * Author:WK   * Time: 2015 3 29 ************************************************************************/ #include"stack.h"    //构造函数,初始化栈的实现Stack::Stack(){   tos=0;   stck[SIZE]=0;}   //向栈中压入数据函数的实现void Stack::push(int ch){   if(tos==SIZE)   {      cout<<"Stack is full!\n";	  return ;   }   stck[tos]=ch;   tos++;   cout<<"You have pushed a data into the Stack!\n";}  //从栈中弹出数据函数的实现int Stack::pop(){   if(0==tos)   {     cout<<"Stack is empty!\n";	 return 0;      }  tos--;  return stck[tos];}//显示栈中数据的函数的实现void Stack::ShowStack(){  cout<<"The content of Stack:\n";	  if(0==tos)	  {	    cout<<"The Stack has no data!\n";		return ;	  }  for(int i=tos-1;i>=0;i--)  {    cout<<stck[i]<<' pre="">

**********************/ #include"stack.h"int main(){ cout<<endl; -----="" :="" a="" again="" an="" case="" ch="toupper(ch);" char="" content="" data="" default="" enter="" from="" have="" i="" int="" iputted="" f="" please="" pop="" pre="" push="" quit="" return="" select="" show="" stack="" that="" the="" to="" try="" value="" want="" wrong="" x="ss.pop();" you=""></p></endl;>

C++ 简单实现压栈出栈 -电脑资料

手机扫码分享

Top