一道有关字符串处理和队列的代码出错。。求助
叶子君 2014-04-17 09:40:29 Project:所谓双端队列(double-ended queue,deque),就是在列表的两端都可以插入和删除数据。
因此它允许的操作有Create、IsEmpty、IsFull、Left、Right、AddLeft、AddRight、DeleteLeft、DeleteRight。
使用循环数组方式实现双端队列,要求实现上述操作,并实现一个Print输出操作,能将队列由左至右的次序输出于一行,元素间用空格间隔。
队列元素类型设为整型。
Input:input.txt,给出一个操作序列,可能是Create、Print之外的任何操作,需要的情况下,会给出参数。最后以关键字“End”结束,例如:
AddLeft 1
AddLeft 2
DeleteRight
IsFull
DeleteLeft
IsEmpty
AddRight 3
AddLeft 2
AddRight 1
End
Output:程序开始执行时,队列设置为空,按输入顺序执行操作,每个操作执行完后,将结果输出于一行。对于错误命令,输出“WRONG”。
对IsEmpty和IsFull命令,试情况输出“Yes”或“No”。
对Left和Right命令,若队列空,输出“EMPTY”,否则输出对应队列元素。
对Add命令,若队列满,输出“FULL”,否则调用Print,输出队列所有元素。
对Del命令,若队列空,输出“EMPTY”,否则输出所有元素。元素间用空格间隔,最后一个元素后不能有空格。最后输出一个回车。
输出示例:
―――――――――
1
2 1
2
No
Yes
3
2 3
2 3 1
――――――――――――――――
问题:编译不通过,主函数部分strcmp报错,不知道肿么改。。;
不确定我这么写这道题对不对,希望有人帮我改下,谢谢
[code=c#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class deque/**************类的声明******************/
{
public:
void Create(int MaxQSize);
void Print(deque &x);
bool IsEmpty(deque &x);
bool IsFull(deque &x);
void Left(deque &x);
void Right(deque &x);
void AddLeft(deque &x,int d);
void AddRight(deque &x,int d);
void DeleteLeft(deque &x);
void DeleteRight(deque &x);
int *a;
int MaxSize;
int front;
int rear;
};
void deque::Create(int MaxQSize)/****************生成函数*******************/
{
MaxSize=MaxQSize+1;
a=new int[MaxSize];
front=rear=0;
}
void deque:: Print(deque &x)/***********************打印*****************************/
{
for (int i=x.front+1;i<=x.rear;i++)
cout<<x.a[i]<<" ";
cout<<endl;
}
bool deque::IsEmpty(deque &x)/**********************判断是否为空*****************************/
{
if (x.front==x.rear)
{
cout<<"Yes"<<endl;
return true;
}
else
{
cout<<"No"<<endl;
return false;
}
}
bool deque::IsFull(deque &x)/********************判断是否已满********************************/
{
if ((x.rear+1)%x.MaxSize==x.front)
{
cout<<"Yes"<<endl;
return true;
}
else
{
cout<<"No"<<endl;
return false;
}
}
void deque::Left(deque &x)
{
if (IsEmpty(x))
{
cout<<"EMPTY"<<endl;
}
else
{
x.Print(x);
}
}
void deque::Right(deque &x)
{
if (IsEmpty(x))
{
cout<<"EMPTY"<<endl;
}
else
{
x.Print(x);
}
}
void deque::AddLeft(deque &x,int d)//对Add命令,若队列满,输出“FULL”,否则调用Print,输出队列所有元素。!!!!!!!!
{
if (IsFull(x))
{
cout<<"FULL"<<endl;
exit (1);
}
else
{
x.rear=(x.rear+1)%x.MaxSize;
for (int i=x.rear;i>front+1;i--)
{
a[i]=a[i-1];
}
a[x.front+1]=d;
x.Print(x);
}
}
void deque::AddRight(deque &x,int d)
{
if (IsFull(x))
{
cout<<"FULL"<<endl;
exit (1);
}
else
{
x.rear=(x.rear+1)%x.MaxSize;
a[x.rear]=d;
x.Print(x);
}
}
void deque::DeleteLeft(deque &x)//对Del命令,若队列空,输出“EMPTY”,否则输出所有元素.
{
if (IsEmpty(x))
{
cout<<"EMPTY"<<endl;
exit (1);
}
else
{
x.front=(x.front+1)%MaxSize;
x.Print(x);
}
}
void deque::DeleteRight(deque &x)//!!!!!!!!!!!!!!!!!!!!1
{
if (IsEmpty(x))
{
cout<<"EMPTY"<<endl;
exit (1);
}
else
{
x.rear=(x.rear-1)%MaxSize;
x.Print(x);
}
}
int main()/*****************主函数******************/
{
fstream fin("input.txt");
string str;
string str1="AddLeft";//1
string str2="AddRight";//2
string str3="IsFull";//3
string str4="IsEmpty";//4
string str5="DeleteRight";//5
string str6="DeleteLeft";//6
string str7="End";//7
deque ts;
ts.Create(6);
int a;
while (!fin.eof())
{
getline(fin,str);
if (! strcmp(str,str1))
{
fin>>a;
ts.AddLeft(ts,a);
}
if (! strcmp(str,&str2))//!!!!!!!!!!!! &
{
fin>>a;
ts.AddRight(ts,a);
}
if (! strcmp(str,&str3))
{
ts.IsFull(ts);
}
if (! strcmp(str,&str4))
{
ts.IsEmpty(ts);
}
if (! strcmp(str,&str5))
{
ts.DeleteRight(ts);
}
if (! strcmp(str,&str6))
{
ts.DeleteLeft(ts);
}
if (! strcmp(str,&str7))
{
break;
}
}
fin.close();
return 0;
}][/code]