• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

大课作业,不会写,请大佬帮忙

使用1维数组实现“优先级队列”,实现好该类后,自己编写主程序验证该类各方法正确性。

struct Queue_entry {

  data_entry data;

   int priority;

};



const int maxqueue = 50; //  small value for testing

class PriorityQueue {

public:

   PriorityQueue();

   bool empty() const;

   Error_code serve();

   Error_code append(const Queue_entry &item);

   Error_code retrieve(Queue_entry &item) const;

protected:

   int  rear;             //  front stays at 0

   Queue_entry entry[maxqueue];

};



PriorityQueue:: PriorityQueue()

/* Post: The PriorityQueue is initialized to be empty. */

{  }



bool PriorityQueue::empty() const

/* Post: Return true if the PriorityQueue is empty, otherwise return false. */

{  }



Error_code PriorityQueue::serve()

/* Post: The front of the PriorityQueue is removed. If the PriorityQueue is empty return an Error_code of underflow. */

{  }



Error_code PriorityQueue::retrieve(Queue_entry &item) const

/*  Post: The front of the PriorityQueue retrieved to the output parameter item. If the PriorityQueue is empty return an Error_code of underflow.  */

{  }



Error_code PriorityQueue::append(const Queue_entry &item)

/*  Post: item is added to the rear of the PriorityQueue and adjust to the proper position by priority field. If the PriorityQueue is full return an Error_code of overflow.*/

{  }


注意:

0号下标为队首元素;

优先级priority的数值越大表明越应放在靠近队首的地方;优先级最高的为队首元素。

实现提示:

插入一个元素时,先放在队尾,之后根据其优先级把它按照类似排序的方法向前移到合适的位置(其后元素优先级小于该元素优先级;其前元素优先级大于或等于该元素优先级)。因此,队列中元素实际上是按照优先级递减的。

删除一个元素时,出队的元素是队列首元(优先级最高的元素)。



数据结构2017级大作业01_测试用例

-------------------------------------------

=========================================

注意:此次检测的例子中,数据为字符:char

=========================================



========

PART 1

========

typedef char data_entry;



========

PART 2

========



int main()

{

    cout

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

请问你解决了吗

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!