数据结构lab04
实验四栈的实现与应用编程题:.设计新接口并在content.cpp文件中测试:1)设计顺序栈的遍历接口 int TraverseStack(SqStack &S);实现栈中数 据按出栈的顺序输出,但保
实验四栈的实现与应用 编程题: 1 .content.cpp 设计新接口并在文件中测试: intTraverseStack(SqStack&S); 1) 设计顺序栈的遍历接口实现栈中数据 按出栈的顺序输出,但保留栈中的数据; //按出栈顺序遍历栈 intTraverseStack(SqStack&S)( if(StackEmpty(S)==1) ( n cout<<"«endl; 栈空 return0;// 栈空,遍历失败 ) for(inti=S.top;i>=0;i—) n cout«S.items[i]«"; cout«endl; return1;//} 遍历成功 intTraverseStack(SNode*top); 2) 设计链栈的遍历接口实现栈中数据 按出栈的顺序输出,但保留栈中的数据; //按出栈顺序遍历栈 intTraverseStack(SNode*top)( if(StackEmpty(top)==l) | cout<v“<<endl; 空栈" return0; 〃空栈,遍历失败 ) ・ SNode*p=top>next; 〃不能移动栈顶指针 while(p) ( nn cout«p->data«;

