请帮看一下为什么不能运行,栈和队列应用

C++语言 码拜 8年前 (2016-04-15) 1015次浏览
#include <iostream>
#include <cstdlib>
using namespace std;
typedef struct QNode{
char  data;
struct QNode *next;
}QNode,*Queueptr;
typedef struct{
Queueptr front;
Queueptr rear;
}linkQueue;
//的定义
typedef struct Strack{
int s[100];
int * base;
int * top;
}Strack,*ST;
//的创建
void InistStract(ST S){
S->base =S->s;
S->top=S->base ;
}
//的判空
bool  StackEmpty(ST S){
if(S->base ==S->top)
return true;
return false;
}
//入
void push(ST S,char e){
* S->top=e;
S->top++;
}
//出
bool pop(ST S,char &e){
if(!StackEmpty( S)){
S->top –;
e=*(S->top );
return true;
}
else{
return false;
}
}
//队列的创建
void Inist(linkQueue &LK){
LK.front =(Queueptr)malloc(sizeof(QNode));
LK.front ->next=NULL;
LK.rear =LK.front ;
}
//队列判空
bool LineEmpty(linkQueue LK){
if(LK.front ==LK.rear )
return true;
return false;
}
//入队
void Push(linkQueue &LK,char e){
LK.rear ->data=e;
LK.rear ->next=(Queueptr)malloc(sizeof(QNode));
LK.rear =LK.rear ->next;
LK.rear ->next=NULL;
}
//出队
void Pop(linkQueue &LK,char &e){
if( !LineEmpty(LK)){
Queueptr p=LK.front ;
while(p->next !=LK.rear ){
p=p->next ;
}
e =p->data ;
free(LK.rear );
LK.rear =p;
}
}
int main(int argc, char** argv) {
linkQueue LK;
ST S;
Inist(LK);
InistStract(S);
char e,c;
cin>>e;
while(e!=”#”) {
push(S,e);
Push(LK,e);
cin>>e;
}
while(! StackEmpty(S)){
pop(S,e);
Pop(LK,c);
if(e!=c){
cout<<“This is not a cycle”<<endl;
break;
}
}
if(StackEmpty(S))
cout<<“This is a cycle”<<endl;
return 0;
}
解决方案

100

队列可以创建是原因是你在队列的初始化函数里为它的成员分配了空间,而你的却没有分配
什么叫s[100]不能直接创建?
代码功能归根结底不是别人帮本人看或讲解或注释出来的;而是被本人静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。
提醒:再牛×的老师也无法代替学生本人领悟和上厕所!
单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明请帮看一下为什么不能运行,栈和队列应用
喜欢 (0)
[1034331897@qq.com]
分享 (0)