第六章 数据抽象-类.pptVIP

  • 4
  • 0
  • 约8.35千字
  • 约 25页
  • 2017-03-26 发布于上海
  • 举报
第六章 数据抽象-类

第六章 数据抽象-类 胡昊 南京大学计算机系软件所 重要内容 栈-过程式 #include iostream using namespace std; //定义栈数据类型 #define STACK_SIZE 100 struct Stack { int top; int buffer[STACK_SIZE]; }; void init(Stack s) { s.top = -1; } bool push(Stack s, int i) { if(s.top==STACK_SIZE-1) { cout “Stack is overflow.\n”; return false; } else { s.top++; s.buffer[s.top] = i; return true; } } bool pop(Stack s, int i) { if(s.top==-1) { cout “Stack is empty.\n”; return false; } else { i=s.buffer[s.top]; s.top--; return true; } } 栈-过程式(使用) //使用栈类型数据 Stack st; int x;

文档评论(0)

1亿VIP精品文档

相关文档