读书人

整了一上午还是有这么多异常初学者

发布时间: 2013-02-04 10:50:21 作者: rapoo

整了一下午,还是有这么多错误,菜鸟求助 (修改)
本帖最后由 liupanmin123456789 于 2013-01-22 20:33:20 编辑 我修改了一下代码,还是那么多错误,求助
#include<iostream>
#include<string>
using namespace std;
const int maxsize=10;
template <class T>

class LinkQueue
{
public:
LinkQueue();
~LinkQueue()
{}


bool EnQueue( const T &item);//入队操作
bool DeQueue( T & item);//出队操作
bool empty()//判断对是否为空
{

return items==0;
}
bool isfull()//判断对是否为满
{

return items==maxsize;
}

private:
class Node
{
public:
T item;
Node *next;
Node(const T &x):item(x),next(0)
{
}
};
Node *rear;
Node *front;
int items;

};
template<class T>
LinkQueue<T>::LinkQueue()
{
Node *s=new Node;
s->next=NULL;
front=rear=s;//定义头节点;
items=0;
}
template <class T>
bool LinkQueue<T>::EnQueue( const T &item)//入队
{
if(isfull())
return false;
Node *data=new node(s);
s->next=NULL;
rear=next=data;
rear=data;
items++;
return true;

}


template <class T>
bool LinkQueue<T>::DeQueue(T &item)//出队
{
if(front==rear)
return 0;
else
{
Node<T>*p=front->next;
item=p->data;
front->next=p->next;
if(p->next==NULL)
rear=front;
delete p;
items--;
return 1;
}

}


void main()
{
LinkQueue<string>Q;

string s;

while(!Q.isfull())//队不满,入队
{
{
cout<<"入队"<<endl;
cout<<"请输入字符串"<<endl;
getline(cin,s);
Q.EnQueue(s);
}
cout<<"队列已满"<<endl;
}
while(!Q.empty())//队不空,出队
{
Q.DeQueue(s);

cout<<s<<endl;
}
}

























[解决办法]
可能是内存问题

读书人网 >C++

热点推荐