首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

整了一上午,还是有这么多异常,初学者 (修改)

2013-02-04 
整了一下午,还是有这么多错误,菜鸟求助 (修改)本帖最后由 liupanmin123456789 于 2013-01-22 20:33:20 编

整了一下午,还是有这么多错误,菜鸟求助 (修改)
本帖最后由 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;
}
}

























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

热点排行