国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

線性表-順序棧

2019-11-08 18:24:56
字體:
來源:轉載
供稿:網友
 #include <iostream> #include <string> #include <vector> #include <algorithm> #define MAXSIZE 100 using namespace std;/*順序棧 */typedef struct{	int *base;//棧底指針 	int *top;//棧頂指針 	int stacksize;//最大容量	}SqStack;//初始化int InitStack(SqStack &S){	S.base = new int[MAXSIZE];	if(!S.base)	{		cout<<"method InitStack() err:內存申請error!"<<endl;		return 0;	}	S.top = S.base;	S.stacksize = MAXSIZE; }  //入棧 int push(SqStack &S,int e) { 	if(S.top-S.base==MAXSIZE) 	{ 		cout<<"method push() err:棧滿error!"<<endl; 		return 0;	 }	 *(S.top++) = e;	 return 1;  }   //取棧頂元素  int getTop(SqStack S)  {  	if(S.top!=S.base)  	{  		return *(S.top-1);	  }	  else	  	return -1;   }    //出棧   int pop(SqStack &S)   {   		if(S.top==S.base)   		{   			cout<<"method pop() err:??誩rror"<<endl;    			return 0;		   }		   int e = *(--S.top);		   return 1;	} int main(){	SqStack stack;	InitStack(stack);	push(stack,1);	push(stack,2);	push(stack,3);	push(stack,4);	push(stack,5);	pop(stack);	cout<<getTop(stack)<<endl;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳浦县| 益阳市| 利津县| 平谷区| 电白县| 兴山县| 乐山市| 象州县| 建湖县| 三穗县| 长葛市| 达孜县| 汉沽区| 高平市| 芜湖县| 赤水市| 绥阳县| 济阳县| 樟树市| 蒙城县| 屏东市| 新田县| 宿迁市| 牟定县| 青州市| 石屏县| 焉耆| 文安县| 高邑县| 镇康县| 新沂市| 垦利县| 吕梁市| 沙田区| 内丘县| 布拖县| 赤峰市| 静安区| 逊克县| 南岸区| 金寨县|