Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a priority queue data structure. Thanks #include // Include to use NULL, otherwise use nullptr #include #include node.hpp template class PQ{ private: Node *head;

Implement a priority queue data structure. Thanks

#include // Include to use NULL, otherwise use nullptr #include #include "node.hpp"

template class PQ{ private: Node *head; // the pointer to the front of the list Node *tail; // the pointer to the back of the list int count;

public: // desc: Inializes a new, empty queue PQ();

// desc: Adds new data to the queue // param: data The data to add to the list // param: priority The priority assigned to this node // returns: void void enqueue(T &data, int priority);

// desc: Removes the front element form the queue // returns: void void dequeue(void);

// desc: Removes the value found at the front of the queue // returns: The data found at the front of the queue T get_front(void);

// desc: Checks if the queue is empty or not // returns: true is the queue is empty, false if not bool isEmpty(void);

// desc: Clears the queue // returns: void void clear(void);

// desc: Returns the number of elements in the queue // returns: The number of elements in the queue int get_count(void); };

template PQ::PQ() { head = NULL; tail = NULL; count = 0; }

template void PQ::enqueue(T &data, int priority) { Node *new_node = new Node(data, priority);

}

template void PQ::dequeue(void) { }

template T PQ::get_front() { }

template bool PQ::isEmpty() { }

template void PQ::clear(void) { }

template int PQ::get_count(void) { }

#pragma once #include template class Node{ private: T data; int priority; Node *next; public: Node(void); Node(T &data); Node(T &data, int prio); void set_data(T &new_data); void set_next(Node *next_node); void set_priority(int prio); T get_data(void); Node *get_next(void); int get_prio(void); };

template Node::Node() { data = 0; priority = 0; next = NULL; }

template Node::Node(T &new_data) { next = NULL; priority = 0; data = new_data; }

template Node::Node(T &new_data, int prio) { next = NULL; data = new_data; priority = prio; }

template void Node::set_data(T &new_data) { data = new_data; }

template T Node::get_data() { return data; }

template void Node::set_next(Node *next_node_ptr) { next = next_node_ptr; }

template Node *Node::get_next() { return next; }

template int Node::get_prio(void) { return priority; }

template void Node::set_priority(int prio) { priority = prio; }

1 1 1 3 1 9 2 3 1 33 3 3 1 2 4 3 1 89 5 3 1 999 0 3 2 3 2 3 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Express the following ratios in its lowest terms. 4 5

Answered: 1 week ago

Question

2. Discuss the types of messages that are communicated nonverbally.

Answered: 1 week ago

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

5. Give examples of variations in contextual rules.

Answered: 1 week ago