百科知识

用数组实现栈的功能的C语言代码?

2018-03-30 05:49:29木***
用数组实现栈的功能的C语言代码?:栈在处理数组上面真的很方便,这是栈的基础方法函数//顺序栈的实现stack.cpp#include "stack.h"Stat?

最佳回答

  •   栈在处理数组上面真的很方便,这是栈的基础方法函数//顺序栈的实现stack。cpp#include "stack。
      h"Status SqStack::InitStack(SqStack **S){ (*S)=(SqStack *) malloc(sizeof(SqStack)); (*S)->base=(SElemType *)malloc(STACKSIZE *sizeof(SElemType)); if(!(*S)->base) exit(OVERFLOW); (*S)->top=(*S)->base; (*S)->stacksize=0; return 1;}Status SqStack::DestroyStack(){free(base);return 1;}Status SqStack::ClearStack(){stacksize=0;return 1;}bool SqStack::StackEmpty(){ if(stacksize==0) return true; else return false;}int SqStack::StackLength(){ return stacksize;}SElemType SqStack::GetTop(){ if(top==base) {cerr<<"空栈!\n";exit(1);} return *(top-1);}Status SqStack::Push(SElemType e){ *(top++)=e;stacksize++; return 1;}SElemType SqStack::Pop(SElemType *e){ if(top==base) {cerr<<"空栈!\n";exit(1);} *e=*--top; stacksize--; return *e;}void SqStack::StackTraverse(void (*visit)(SElemType *)){while(top!=base){ stacksize--;visit(--top);}}。
    2018-03-30 08:08:28
  • 很赞哦! (288)