Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]:Adding Priority Queue in C #431

Open
DinkyRajpoot56 opened this issue Oct 26, 2024 · 0 comments
Open

[Feature Request]:Adding Priority Queue in C #431

DinkyRajpoot56 opened this issue Oct 26, 2024 · 0 comments

Comments

@DinkyRajpoot56
Copy link

A priority queue is an abstract data type that behaves similarly to the normal queue except that each element has some priority, i.e., the element with the highest priority would come first in a priority queue. The priority of the elements in a priority queue will determine the order in which elements are removed from the priority queue.

The priority queue supports only comparable elements, which means that the elements are either arranged in an ascending or descending order.

For example, suppose we have some values like 1, 3, 4, 8, 14, 22 inserted in a priority queue with an ordering imposed on the values is from least to the greatest. Therefore, the 1 number would be having the highest priority while 22 will be having the lowest priority.

int parent(int i): This function returns the index of the parent node of a child node, i.e., i.
int left_child(int i): This function returns the index of the left child of a given index, i.e., i.
int right_child(int i): This function returns the index of the right child of a given index, i.e., i.
void moveUp(int i): This function will keep moving the node up the tree until the heap property is restored.
void moveDown(int i): This function will keep moving the node down the tree until the heap property is restored.
void removeMax(): This function removes the element which is having the highest priority.
void insert(int p): It inserts the element in a priority queue which is passed as an argument in a function.
void delete(int i): It deletes the element from a priority queue at a given index.
int get_Max(): It returns the element which is having the highest priority, and we know that in max heap, the root node contains the element which has the largest value, and highest priority.
int get_Min(): It returns the element which is having the minimum priority, and we know that in max heap, the last node contains the element which has the smallest value, and lowest priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant