#include <iostream.h>
#include <stdlib.h>

const int MaxPQSize = 50;
typedef int DataType;

class PQueue
{
 private:
  int count;
  DataType pqlist[MaxPQSize];

 public:
  PQueue(void);
  void PQInsert(const DataType& item);
  DataType PQDelete(void);
  void ClearPQ(void);

  int PQEmpty(void) const;
  int PQFull(void) const;
  int PQLength(void) const;
};

void PQueue::PQInsert(const DataType& item)
{
 if (count == MaxPQSize)
 {
  cerr << "Priority queue overflow!" << endl;
  exit(1);
 }

 pqlist[count] = item;
}

DataType PQueue::PQDelete(void)
{
 DataType min;
 int i, minindex = 0;

 if (count > 0)
 {
  min = pqlist[0];

  for (i = 1; i < count; i++)
  {
   if (pqlist[i] < min)
   {
    min = pqlist[i];
    minindex = i;
   }
  }

  pqlist[minindex] = pqlist[count];
  count--;
 }
 else
 {
  cerr << "Deleting from an empty pqueue!";
  exit(1);
 }

 return min;
}

posted on 2007-11-21 22:45  IT Person  阅读(259)  评论(0)    收藏  举报