求大神帮忙啊 愁死啦
#include<iostream>
using namespace std;
#include<stdlib.h>
#include <time.h>
#include<string.h>
#define SIZE 4
typedef struct Car1
{
char number[15];
int artime;
int letime;
}CarNode;
typedef struct
{
CarNode *base;
CarNode *top;
int stacksize;
}Park;
typedef struct Car2
{
char number[15];
int ar_time;
struct Car2 *next;
}*CarPtr;
typedef struct
{
CarPtr front;
CarPtr rear;
int length;
}Shortcut;
int Initstack(Park &P) //初始化停车场
{
P.base =new Car1;
P.top =P.base ;
P.stacksize =0;
return 1;
}
int Push(Park &P,CarNode &e)
{
++P.top ;
*P.top =e;
++P.stacksize ;
return 1;
}
int Pop(Park &P,CarNode &e)
{
if(P.top ==P.base )
cout<<"停车场为空。"<<endl;
else{
e=*P.top--;
--P.stacksize ;
}
return 1;
}
int InitQueue(Shortcut &S)
{
S.front =S.rear =new Car2;
S.front->next =NULL;
S.length =0;
return 1;
}
int EnQueue(Shortcut &S,char number[]) //队列,尾进,头出,top->next,为第一个数
{
CarPtr p;
p=new Car2;
strcpy(p->number,number);
p->next=NULL;
S.rear->next=p;
S.rear=p;
++S.length;
return 1;
}
void DeQueue(Shortcut &S,CarPtr &w)
{
if(S.length ==0)
cout<<"此便道为空"<<endl;
else{
w=S.front->next ;
S.front->next =w->next ;cout<<"------//"<<endl;
--S.length;
}
}void Arrival(Park &P,Shortcut &S)
{
cout<<"------//"<<endl;
cout<<"------//"<<endl;
// time_t timep;
// struct tm *m;
// time (&timep);
// m=gmtime(&timep);
char number[15];
cout<<"\n请输入车牌号:"<<endl;
cin>>number;;
if(P.stacksize<SIZE )
{
CarNode b;
// b.artime =m->tm_mday*24*60+m->tm_hour*60+m->tm_min;
strcpy(b.number,number);
Push(P,b);
cout<<"\n该车停在第"<<P.stacksize <<"号车道"<<endl;
}
else{
cout<<"------//"<<endl;
EnQueue(S,number);
cout<<"\n停车场已经满了,该车停在便道的第"<<S.length <<"个位置"<<endl;
}
}
void Leave(Park &P,Park &Q,Shortcut &S)
{
// time_t timep;
// struct tm *m;
// struct tm *n;
// time (&timep);
// m=gmtime(&timep);
// n=gmtime(&timep);
char number1[15];
int i,a,x;
CarNode e,e1,e2;
CarPtr w;
cout<<"\n请输入离开车辆的车牌号:"<<endl;
cin>>number1 ;
while(1)
{
if(strcmp(P.top->number ,number1)!=0 ){
if(P.stacksize ==0){
cout<<"\n停车场已空!"<<endl;
break;
}
Pop(P,e);
Push(Q,e);
a=1;
cout<<"qqq"<<endl;
}
else{
Pop(P,e1);
cout<<"\n车牌号为"<<e1.number <<"的车已离开。"<<endl;
// e1.letime =m->tm_mday*24*60+m->tm_hour*60+m->tm_min ;
// x=(e1.letime -e1.artime) %60;
// if(x!=0) x= (e1.letime -e1.artime) /60+1;
// cout<<"\n缴费"<< x<<"元。"<<endl;
break;
}
}
if(a!=0){
while(1)
{
Pop(Q,e);
Push(P,e);
cout<<11<<endl;
if(Q.stacksize ==0)
break;
}
}
//车出栈的已经写完,出队列近战额还没写。。
if(S.length !=0){ cout<<"+++++++++++++"<<endl;
DeQueue(S,w);
cout<<"+++++++++++++"<<endl;
strcpy(e2.number ,w->number);
// e2.artime =n->tm_mday*24*60+n->tm_hour*60+n->tm_min ;
Push(P, e2);
cout<<"\n车牌号为"<<w->number <<"的车由便道开进停车场。"<<endl;
}
}
int main()
{
int m;
Park P,Q;
Shortcut S;
Initstack(P);
Initstack(Q);
InitQueue(S);
while(2)
{
cout<<"\n\t$ 1 进入停车场 $\n"<<endl;
cout<<"\t$ 2 离开停车场 $\n"<<endl;
cout<<"\t$ 3 ===退出=== $\n\n"<<endl;
cout<<"\t请输入:"<<endl;
cin>>m;
switch(m){
case 1:
Arrival(P,S);
break;
case 2:
Leave(P,Q,S);
break;
case 3:
break;
default:
cout<<"请输入正确的选项。" <<endl;
break;
}
if(m==3)break;
}
}
编的这个程序,编译没毛病,运行后,当栈范围大于3时,删除栈内其中一个值,进行队列头的值压入栈中就没法实现了,好忧桑啊