头文件假设名字是:queue.h ,如下:
#include"stdio.h"
#include"iostream"
using namespace std;
struct Node
{
int data;
Node* next;
Node(){
next = NULL;
}
};
class Queue
{
public: // constuctor
Queue();
bool empty()const;
void push(const int item);// Put the data in the rear of queue
int getFront();// Get the first data in the queue
void pop();// Pop the first data
int getSize();// Get the size of queue
protected:
Node *front, *rear; int count;
};
源文件:
#include"queue.h"
Queue::Queue()
{
front = rear 0;
count = 0;
}
int Queue::getSize()
{
return count;
}
这个是要用链表来实现一个队列,应该不难的啊。用链表实现堆栈的话应该是反着的,如果队列就用正常的行的,你可以试一下,我也按你说的打打看。
你还有代码没?只看头文件,怎么给你解释呢?