⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.h

📁 一个linux下的各种组播路由算法编程
💻 H
字号:
/*****************************************************************************
***                      Author: Hussein F. Salama                         ***
***                       Date: September 9, 1994                          ***
***                            File: queue.h                               ***
***  A C++ library of classes to represent FIFO queues and priority queues ***    
*****************************************************************************/
#ifndef QUEUE_H
#define QUEUE_H

#include <stdlib.h>
#include "data.h"
#include <stdio.h>

// To describe the status of the queue

#define WasFull    0
#define WasNotFull 1

// Define the size of each output queue

#define QMAX  8

class Queue {

   protected:
        int  packets_inq;
	int  q_max;

   public:
      Queue() { q_max = QMAX; };
      virtual ~Queue() {};
      virtual int add_to_q(Data d) = 0;     
      virtual Data remove_from_q() = 0;     
      virtual int packetsInQ() { return(packets_inq); };
      virtual void clearQ() = 0; 
      virtual int QisMT() = 0;
      virtual DataList *head() = 0;
      virtual int size() { return(q_max); };
      virtual void size(int s) = 0;
};


class FIFOQueue : public Queue {   // A FIFO queue that holds data packets

   private:
	DataList *hd, *tl;    // queue head and queue tail
   public:
        FIFOQueue() { hd = tl = NULL; packets_inq = 0; };
        ~FIFOQueue();
        int add_to_q(Data d);   // add a data packet to the queue
        Data remove_from_q();     // remove a data packet from the queue
        DataList *head() { return(hd); };
        DataList *tail() { return(tl); };
        void clearQ(); //removes all packets in the queue
        int QisMT() { if (hd == NULL) return(1); else return(0); };
        void size(int s) { q_max = s; };
}; //FIFOQueue;

class QueueListEntry {

   private:
        FIFOQueue *q;
        QueueListEntry *n;
        int pr;

   public:
        QueueListEntry(int p) { q = new FIFOQueue(); 
                                       n = NULL; pr = p; };
        ~QueueListEntry() { delete q; };
        Queue *queue() { return(q); };
        void queue(FIFOQueue *qq) { q = qq; };
        QueueListEntry *next() { return(n); };
        void next(QueueListEntry *nn) { n = nn; };
        int priority() { return(pr); };

}; //QueueLisEntry

class PriorityQueue : public Queue { 

   private:
        QueueListEntry *highestPrQ;    //Each priority level is a 
                                       //separate FIFO queue
        int   levels;                  //Number of priority levels
   public:
        PriorityQueue(int l);
        ~PriorityQueue();
        int add_to_q(Data d);     // add a data packet to the queue
        Data remove_from_q();     // remove a data packet from the queue
        void clearQ(); //removes all packets in the queue
        int QisMT() { if (packets_inq == 0) return(1); else return(0); };
        DataList *head();
        void size(int s);

}; //PriorityQueue


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -