基本操作 ①初始化 StatusInitStack(SqStack&S) {//构造一个空栈S Sbase=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!Sbase)exit(OVERFLOW);//分配失败 Stop=Sbase; Sstacksize=STACK_INIT_SIZE; returnOK; } ②入栈 StatusPush(SqStack&SSElemTypee){ if(StopSbase>=Sstacksize){ //栈满追加存储空间 Sbase=(SElemType*)realloc(Sbase (Sstacksize+STACKINCREMENT)*sizeof(SElemType)); if(!Sbase)exit(OVERFLOW); //存储分配失败 Stop=Sbase+Sstacksize; Sstacksize+=STACKINCREMENT; } *Stop++=e; returnOK; } ③出栈 StatusPop(SqStack&SSElemType&e){ //若栈不空则删除S的栈顶元素 //用e返回其值并返回OK //否则返回ERROR if(Stop==Sbase)returnERROR; e=*Stop; returnOK; } 返回《数据结构》考研复习精编 [] [] [] [] [] [] [] [] [] |