Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Node{
- public:
- double data;
- int priority;
- Node* next;
- };
- class Queue{
- Node* head;
- public:
- Queue(){
- head = NULL;
- }
- void Enqueue(double data, int p){
- Node* NewNode = new Node();
- NewNode->data = data;
- NewNode->next = NULL;
- if (p == 1 || p == 0){
- NewNode->next = head;
- head = NewNode;
- }
- else{
- Node* temp = head;
- int counter = 2;
- while((p > counter) && temp){
- temp = temp->next;
- counter ++;
- }
- NewNode->next = temp->next;
- temp->next = NewNode;
- }
- }
- void Dequeue(){
- Node* temp = new Node();
- temp = head;
- head = temp->next;
- delete(temp);
- }
- void Display(){
- Node* temp = head;
- while(temp){
- cout<<temp->data<<" ";
- temp = temp->next;
- }
- cout<<endl;
- }
- };
- int main(){
- Queue ob;
- ob.Enqueue(5,0);
- ob.Display();
- ob.Enqueue(9,1);
- ob.Display();
- ob.Enqueue(4,2);
- ob.Display();
- ob.Enqueue(3,3);
- ob.Display();
- ob.Enqueue(8,4);
- ob.Display();
- ob.Enqueue(10,6);
- ob.Display();
- ob.Dequeue();
- ob.Display();
- ob.Enqueue(16,4);
- ob.Display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement