求各位大神解答。帮忙修改,求答案啊!!!
#include<iostream>#include<string.h>usingnamespacestd;constintsize=10;classqueue{intQ...
#include<iostream>
#include<string.h>
using namespace std;
const int size=10;
class queue{
int Q[size];
int front;
int rear;
public:
queue(); //构造空队列
~queue(); //销毁队列
int enter(int a); //入队
int exit(); //出队
int clear(); //清空队列
};
#include"1.h"
queue::queue()
{front=rear=0;
}
queue::~queue()
{
}
int queue::enter(int a)
{if((rear+1)%size==front)
{cout<<"This queue is full";
return 0;}
Q[rear]=Q[0];
rear=(rear+1)%size;
return 1;}
int queue::exit()
{if(front==rear) return 0;
Q[0]=Q[front];
front=(front+1)%size;
return 1;}
int queue::clear()
{while(front=rear)
memset(Q,0,size);
return 1;
}
#include"1.h"
int main()
{
cout<<endl;
queue a;
int b;
char c;
cout<<"<J>----enter data to queue"<<endl;
cout<<"<C>----exit data from queue"<<endl;
cout<<"<Q>----clear the queue"<<endl;
cout<<"<T>----Quit...."<<endl;
while(1)
{
cout<<"Please select an item:";
cin>>c;
c=toupper(c);
switch(c)
{
case 'J':
cout<<"Enter the value that "<<"you want to push:";
cin>>b;
a.enter(b);
break;
case 'C':
b=a.exit();
cout<<"exit"<<b<<"from queue"<<endl;
break;
case 'Q':
cout<<"The queue is empty"<<endl; //为什么这里我就不能调用clear()函数呢??
break;
case 'T':
return 0;
default:
cout<<"You have inputted a wrong item! Pelase try again"<<endl;
continue;
}
}
return 0;
} 展开
#include<string.h>
using namespace std;
const int size=10;
class queue{
int Q[size];
int front;
int rear;
public:
queue(); //构造空队列
~queue(); //销毁队列
int enter(int a); //入队
int exit(); //出队
int clear(); //清空队列
};
#include"1.h"
queue::queue()
{front=rear=0;
}
queue::~queue()
{
}
int queue::enter(int a)
{if((rear+1)%size==front)
{cout<<"This queue is full";
return 0;}
Q[rear]=Q[0];
rear=(rear+1)%size;
return 1;}
int queue::exit()
{if(front==rear) return 0;
Q[0]=Q[front];
front=(front+1)%size;
return 1;}
int queue::clear()
{while(front=rear)
memset(Q,0,size);
return 1;
}
#include"1.h"
int main()
{
cout<<endl;
queue a;
int b;
char c;
cout<<"<J>----enter data to queue"<<endl;
cout<<"<C>----exit data from queue"<<endl;
cout<<"<Q>----clear the queue"<<endl;
cout<<"<T>----Quit...."<<endl;
while(1)
{
cout<<"Please select an item:";
cin>>c;
c=toupper(c);
switch(c)
{
case 'J':
cout<<"Enter the value that "<<"you want to push:";
cin>>b;
a.enter(b);
break;
case 'C':
b=a.exit();
cout<<"exit"<<b<<"from queue"<<endl;
break;
case 'Q':
cout<<"The queue is empty"<<endl; //为什么这里我就不能调用clear()函数呢??
break;
case 'T':
return 0;
default:
cout<<"You have inputted a wrong item! Pelase try again"<<endl;
continue;
}
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询