الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيفية عمل Darive ل Priority Queue Implementation

بدأه هاوي العماني في 24 نوفمبر 2008 · 0 رد · 584 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكــم ورحمـة الله وبركاتــه

أنا عندي أستفسار في دالة

Priority Queue

من خلال هذا السوال ..حاولت أحل بس في deuge

هذا السوال مرفوق بحلي...

والمشكلة عندي في Main Draive

A simple queue can be modeled by a data structure that allows the insertion of elements at the back of the container (the enqueue operation) and extracts information from the front of the container (the dequeue operation). The actual storage mechanism used to manage and contain the information is an implementation detail that is not that important to the user of the queue. Perhaps, the information is managed by a linked list or a dynamically sizable array or vector.

This assignment will require you to implement a class that supports a queue with priority. Your priority queue should support the insertion of elements into the queue based on one of three priorities

- low: for a low priority -normal: for a normal priority -high: for a high priority

When removing items from the queue, items with a higher priority are removed first, however, items with the same priority are removed from the queue using the standard FIFO ordering. The data types supported by your queue should be positive integers. Your class implementation should also dynamically manage the amount of information that it is containing. For example, your class should support adding 200 elements to the queue before any of them are removed.

Directions: The first thing that you should do is to define some constants that class users can reference to indicate the priority of the elements that they are enqueueing.

#define PRIORITY_LOW 1

#define PRIORITY_NORMAL 2

#define PRIORITY_HIGH 3

Once your constants are defined your priority queue class should support the following public operations:

int Enqueue(int Data, int Priority): This method inserts the element Data onto the priority queue with the specified priority. This method should return a TRUE (non zero) return code if it succeeds or a FALSE (a zero) if it fails.

int Enqueue(int Data): This method inserts the element Data onto the priority queue with a PRIORITY_NORMAL priority. It should return the same return code information as the Enqueue() method that supports the priority.

int Dequeue():This method removes the appropriate element from the queue and returns it to the caller. If the queue is empty (or if an error occurs) this method should return a negative return code. The return codes for this method should be clearly documented to indicate the cause of the failure (e.g, #define E_EMPTY_QUEUE -1).

int Peek(): This method works the same as the Dequeue() method except that it does not remove the element from the queue. It simply returns to the caller the element on the top of the queue without removing it! If the queue is empty (or if an error occurs) this method should return a negative return code. The return codes for this method should be clearly documented to indicate the cause of the failure (e.g, #define E_EMPTY_QUEUE -1).

int Count(): This method returns the current number of elements stored in the queue.

Other Considerations

The operations specified in the previous section represent the public interface of your priority queue class. You may feel free to implement as many private methods as you need to properly support the behavior of the priority queue. You may also use any algorithm that you want to act as the storage container for the data stored in the queue (e.g., dynamic array, linked-list).

Your priority queue class should also be sensitive to preventing memory leaks. That is any storage allocated in you priority queue class should be automatically deallocated when priority queue objects are destroyed or go out of scope (Hint: use the destructor).

PQueue.rar

مواضيع مشابهة