?? stack2.cpp
字號:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>
//#include<alloc.h>
#include<process.h>
#define mySIZE 100;
#define ENT 10;
#define OK 1
#define ERROR 0
#define OVERFLOW -1
typedef int Status;
typedef char ElemType;
typedef char SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S){
S.base=(SElemType *)malloc(100*sizeof(ElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=mySIZE;
return OK;
}
Status Push(SqStack &S,SElemType e){
if (S.top-S.base>=S.stacksize){
S.base=(ElemType*)realloc(S.base,(S.stacksize+10)*sizeof(ElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=10;
}
*S.top++=e;
return OK;
}
Status Pop(SqStack &S,SElemType &e){
if(S.top==S.base) return ERROR;
e=*--S.top;
return OK;
}
Status GetTop(SqStack S,SElemType &e){
if (S.top==S.base) return ERROR;
e = *(S.top-1);
printf("e=%c",e);
return OK;
}
main()
{
SqStack s;
ElemType e;
InitStack(s);
Push(s,'9');
GetTop(s,e);
Push(s,'5');
Pop(s,e);
return OK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -