Ma travis huston x (B Grades CS 2433-0 C x Home zy Books zy Oklahoma State Unive
ID: 3813912 • Letter: M
Question
Ma travis huston x (B Grades CS 2433-0 C x Home zy Books zy Oklahoma State Universi x c Secure l https://myzybooks.com/w/zybookyoKs TATECS2433Chan-Tinspring2017/chapter/16/section/13 VERIFY EMAIL A 16.12 Homework8 (due Apr 1) 16.13 Homework9 (due Apr 8) Students This content is your instructor and is not content questions or concerns about this content to your instructor If you have any technical issues with the zyLab submission system, use the "Trouble with lab' button at bottom the lab. Implement a Priority Queue for strings. A priority queue is similar to a regular queue except each item added to the queue also has an associated priority For this problem, make the priority an integer where 0 is the highest priority and larger values are increasingly lower in The remove function should return and removethe itemthat has the highest priority. For example: q add("X", 10) q-add("Y", 1); q add ("Z", 3) cout q-renove Returns Y cout q remove Returns Z cout q remove Returns X You can implement the priority queue by performing a linear search in the remove0 function. Hint Take a look at the Linked List code example from 03/30, which can downloaded from D2L Reusing the code example is acceptable and modifying it is acceptable. You are expected to use pointers. You will get a 0 if you use STL priority queue or any other already-implemented priority queue data Important Make sure to use the template provided since the test cases depend on it Submission 16.13.1: Homework9 (due Apr 8) main.cpp Load default template. 1 ainelude kiostrearo 2 einclude string> ainclude est dlib. 5 using namespace std;Explanation / Answer
#include <iostream>
#include <cstdlib>
#define MAX_VALUE 65536
using namespace std;
/* category Node */
class Node
;
/* category ThreadedBinarySearchTree */
class ThreadedBinarySearchTree
builder */
ThreadedBinarySearchTree()
/* perform to clear tree */
void makeEmpty()
/* perform to insert a key */
void insert(int key)
else if (p->key > key)
else
}
Node *tmp = new Node();
tmp->key = key;
tmp->rightThread = tmp->leftThread = true;
if (p->key < key)
facet */
tmp->right = p->right;
tmp->left = p;
p->right = tmp;
p->rightThread = false;
}
else
}
/* perform to look for a part */
bool search(int key)
come false;
tmp = tmp->right;
}
else if (tmp->key > key)
come false;
tmp = tmp->left;
}
else
come true;
}
}
}
/* Fuction to delete a part */
void Delete(int key)
else if (dest->key > key)
else
}
Node *target = dest;
if (!dest->rightThread && !dest->leftThread)
2 children*/
p = dest;
/* realize largest node at left kid */
target = dest->left;
whereas (!target->rightThread)
/* exploitation replace mode*/
dest->key = target->key;
}
if (p->key >= target->key)
else if (target->rightThread)
{
Node *largest = target->left;
whereas (!largest->rightThread)
largest->right = p;
p->left = target->left;
}
else
{
Node *smallest = target->right;
whereas (!smallest->leftThread)
smallest->left = target->left;
p->left = target->right;
}
}
else
else if (target->rightThread)
{
Node *largest = target->left;
whereas (!largest->rightThread)
largest->right = target->right;
p->right = target->left;
}
else
{
Node *smallest = target->right;
whereas (!smallest->leftThread)
smallest->left = p;
p->right = target->right;
}
}
}
/* perform to print tree */
void printTree()
{
Node *tmp = root, *p;
for (;;)
{
p = tmp;
tmp = tmp->right;
if (!p->rightThread)
{
whereas (!tmp->leftThread)
}
if (tmp == root)
break;
cout<<tmp->key<<" ";
}
cout<<endl;
}
};
/* Main Contains Menu */
int main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.