C++实现队列问题,头文件已给出

2025-03-12 09:36:26
推荐回答(3个)
回答1:

头文件假设名字是: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;
 }

回答2:

这个是要用链表来实现一个队列,应该不难的啊。用链表实现堆栈的话应该是反着的,如果队列就用正常的行的,你可以试一下,我也按你说的打打看。

回答3:

你还有代码没?只看头文件,怎么给你解释呢?