哪位高手帮小弟我看看这个链式队列错在哪儿
谁帮我看看这个链式队列错在哪儿?
------解决方案--------------------
//file :queue_link.h
#ifndef _QUEUE_LINK_H_HUMING_INCLUDE_
#define _QUEUE_LINK_H_HUMING_INCLUDE_
#include<cstdio>
template <class T>
class node
{
public:
T data;
node<T>* next;
node():next(NULL) {}; //No-arg constructor
node(T p)//Constructor
{
this->data=p;//"this" means "class node"
next=NULL;
};
};
//node defination
template <class T>
class queue
{
public:
queue();
bool empty();
void pop();
void push(T x);
T front();
private:
node<T> *frount,*rear;
};
template <class T>
void queue<T>::push(T x)
{
node<T> *q=new node<T>;
q->data=x;
q->next=NULL;
rear->next=q;
rear=q;
}
template <class T>
queue<T>::queue()
{
node<T>* frount=new node<T>;
frount->next=NULL;
rear=frount;
}
template <class T>
bool queue<T>::empty()
{
if(rear==frount) return true;
else return false;
}
template <class T>
void queue<T>::pop()
{
if(!empty())
{
node<T>* x;
x=frount->next;
frount->next=x->next;
if(x->next==NULL) rear=frount;
delete x;
}
}
template <class T>
T queue<T>::front()
{
if(frount->next!=NULL)return (frount->next->data);
}
#endif
------解决方案--------------------
//file :queue_link.h
#ifndef _QUEUE_LINK_H_HUMING_INCLUDE_
#define _QUEUE_LINK_H_HUMING_INCLUDE_
#include<cstdio>
template <class T>
class node
{
public://why don't you declare "data" and "next" as private?
T data;
node<T>* next;
node():next(NULL) {}; //No-arg constructor
node(T p)//Constructor
{
this->data=p;//"this" means "class node"
next=NULL;
};
};
//node defination
template <class T>
class queue
{
public:
queue();
~queue();