主题:停车场系统
大家给看看这个程序,没有错误,就是运行时老停止工作,不知道怎么弄,谢谢喽
#include "stdafx.h"
#define stacksize 3
#define queuesize n
typedef struct LNode
{
int data;
struct LNode *next;
}*Squeue;
Squeue *f,*r;
int ts[stacksize],ps[stacksize];
int top;
int temp,number;
bool out;
char ch;
void Pushstack(int s[],int x)
{
if(top==stacksize)
printf("man");
else
{ s[top]=x;
top++;
}
}
void popstack(int s[])
{
if(top==0)
printf("underflow");
else
top=top-1;
}
bool emptystack(int s[])
{
if(top==0)
return true;
else
return false;
}
int topstack(int s[])
{
return s[top];
}
void initstack(int s[])
{
s=NULL;
}
void Initque(Squeue f,Squeue r)
{
f=new LNode;
r=f;
f->next=NULL;
}
void inque(Squeue f,Squeue r,int x)
{
Squeue p;
p=new LNode;
p->data=x;
p->next=NULL;
r->next=p;
r=p;
}
void outque(Squeue f,Squeue r)
{
Squeue p;
if(f==r)
printf("kong");
else
{
p=f->next;
f->next=p->next;
if(p->next==NULL)
r=f;
delete(p);
}
}
int getheadque(Squeue f)
{
Squeue p;
f->next=p;
return(p->data);
}
bool emptyque(Squeue f,Squeue r)
{
if(f==r)
return true;
else
return false;
}
void main()
{
initstack(ts);
initstack(ps);
Initque(*f,*r);
out=false;
scanf("%c","%d",ch,number);
while(number>0)
{
switch(ch)
{
case'a':
printf("车来了");
if(top==stacksize)
inque(*f,*r,number);
else
Pushstack(ps,number);
case'd':
{
while((!emptystack(ps))&&(topstack(ps)!=number))
{
temp=topstack(ps);
popstack(ps);
Pushstack(ts,temp);
}
if (emptystack(ps))
{
printf("停车场无此车");
}
else
{
printf("%d",topstack(ps));
out=true;
}
while(!emptystack(ts))
{
temp=topstack(ts);
popstack(ts);
Pushstack(ps,temp);
}
if(out&&emptyque(*f,*r))
{
temp=getheadque(*f);
outque(*f,*r);
out=false;
Pushstack(ps,temp);
}
}
}
scanf("%c","%d",ch,number);
}
}
#include "stdafx.h"
#define stacksize 3
#define queuesize n
typedef struct LNode
{
int data;
struct LNode *next;
}*Squeue;
Squeue *f,*r;
int ts[stacksize],ps[stacksize];
int top;
int temp,number;
bool out;
char ch;
void Pushstack(int s[],int x)
{
if(top==stacksize)
printf("man");
else
{ s[top]=x;
top++;
}
}
void popstack(int s[])
{
if(top==0)
printf("underflow");
else
top=top-1;
}
bool emptystack(int s[])
{
if(top==0)
return true;
else
return false;
}
int topstack(int s[])
{
return s[top];
}
void initstack(int s[])
{
s=NULL;
}
void Initque(Squeue f,Squeue r)
{
f=new LNode;
r=f;
f->next=NULL;
}
void inque(Squeue f,Squeue r,int x)
{
Squeue p;
p=new LNode;
p->data=x;
p->next=NULL;
r->next=p;
r=p;
}
void outque(Squeue f,Squeue r)
{
Squeue p;
if(f==r)
printf("kong");
else
{
p=f->next;
f->next=p->next;
if(p->next==NULL)
r=f;
delete(p);
}
}
int getheadque(Squeue f)
{
Squeue p;
f->next=p;
return(p->data);
}
bool emptyque(Squeue f,Squeue r)
{
if(f==r)
return true;
else
return false;
}
void main()
{
initstack(ts);
initstack(ps);
Initque(*f,*r);
out=false;
scanf("%c","%d",ch,number);
while(number>0)
{
switch(ch)
{
case'a':
printf("车来了");
if(top==stacksize)
inque(*f,*r,number);
else
Pushstack(ps,number);
case'd':
{
while((!emptystack(ps))&&(topstack(ps)!=number))
{
temp=topstack(ps);
popstack(ps);
Pushstack(ts,temp);
}
if (emptystack(ps))
{
printf("停车场无此车");
}
else
{
printf("%d",topstack(ps));
out=true;
}
while(!emptystack(ts))
{
temp=topstack(ts);
popstack(ts);
Pushstack(ps,temp);
}
if(out&&emptyque(*f,*r))
{
temp=getheadque(*f);
outque(*f,*r);
out=false;
Pushstack(ps,temp);
}
}
}
scanf("%c","%d",ch,number);
}
}