EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134996066
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 21, Problem 7PC
Program Plan Intro
Queue Converter
Program Plan:
DynIntQueue.h:
- Include required header files.
- Declare a class named “DynIntQueue”; inside the class,
- Inside the “private” access specifier,
- Create a structure named “QueueNode”.
- Declare a variable “value”.
- Create a pointer named “next”.
- Create two pointers named “front” and “rear”.
- Declare a variable “numItems”.
- Create a structure named “QueueNode”.
- Inside “public” access specifier,
- Declare constructor and destructor.
- Declare the functions “enqueue()”, “dequeue()”, “isEmpty()”, “isFull()”, and “clear()”.
- Inside the “private” access specifier,
DynIntQueue.cpp:
- Include required header files.
- Give definition for the constructor.
- Assign the values.
- Give definition for the destructor.
- Call the function “clear()”.
- Give function definition for “enqueue()”.
- Make the pointer “newNode” as null.
- Assign “num” to “newNode->value”.
- Make “newNode->next” as null.
- Check whether the queue is empty using “isEmpty()” function.
- If the condition is true then, assign “newNode” to “front” and “rear”.
- If the condition is not true then,
- Assign “newNode” to “rear->next”.
- Assign “newNode” to “rear”.
- Increment the variable “numItems”.
- Give function definition for “dequeue()”.
- Assign “temp” pointer as null.
- Check if the queue is empty using “isEmpty()” function.
- If the condition is true then print “The queue is empty”.
- If the condition is not true then,
- Assign the value of front to the variable “num”.
- Make “front->next” as “temp”.
- Delete the front value.
- Make temp as front.
- Decrement the variable “numItems”.
- Give function definition for “isEmpty()”.
- Assign “true” to a Boolean variable
- Check if “numItems” is true.
- If the condition is true then assign “false” to the variable.
- Return the Boolean variable.
- Give function definition for “clear()”.
- Declare a variable.
- Dequeue values from queue till the queue becomes empty using “while” condition.
- Declare a variable.
IntBinaryTree.h:
- Include required header files.
- Declare a class named “IntBinaryTree”. Inside the class,
- Inside the “private” access specifier,
- Give the structure declaration for the creation of node.
- Declare a variable
- Create two pointers named “left” and “right” to access the value left and right nodes respectively.
- Create a pointer named “root” to access the value of root node.
- Give function declaration for “insert ()”, “destroy_SubTree ()”, “delete_Node ()”, “make_Deletion ()”, “display_InOrder ()”, “display_PreOrder ()”, “display_PostOrder ()”, “copyTree ()”, and “setQueue ()”.
- Give the structure declaration for the creation of node.
- Inside “public” access specifier,
- Give the definition for constructor and destructor.
- Give function declaration for binary tree operations.
- Inside the “private” access specifier,
IntBinaryTree.cpp:
- Include required header files.
- Give definition for copy constructor.
- Give function definition for “insert()”.
- Check if “nodePtr” is null.
- If the condition is true then, insert node.
- Check if value of new node is less than the value of node pointer
- If the condition is true then, Insert node to the left branch by calling the function “insert()” recursively.
- Else,
- Insert node to the right branch by calling the function “insert()” recursively.
- Check if “nodePtr” is null.
- Give function definition for “insert_Node ()”.
- Create a pointer for new node.
- Assign the value to the new node.
- Make left and right node as null.
- Call the function “insert()” by passing parameters “root” and “newNode”.
- Give function definition for “destroy_SubTree()”.
- Check if the node pointer points to left node
- Call the function recursively to delete the left sub tree.
- Check if the node pointer points to the right node
- Call the function recursively to delete the right sub tree.
- Delete the node pointer.
- Check if the node pointer points to left node
- Give function definition for “search_Node()”.
- Assign false to the Boolean variable “status”.
- Assign root pointer to the “nodePtr”.
- Do until “nodePtr” exists.
- Check if the value of node pointer is equal to “num”.
- Assign true to the Boolean variable “status”
- Check if the number is less than the value of node pointer.
- Assign left node pointer to the node pointer.
- Else,
- Assign right node pointer to the node pointer.
- Check if the value of node pointer is equal to “num”.
- Return the Boolean variable.
- Give function definition for “remove()”.
- Call the function “delete_Node()”
- Give function definition for “delete_Node()”
- Check if the number is less than the node pointer value.
- Call the function “delete_Node()” recursively.
- Check if the number is greater than the node pointer value.
- Call the function “delete_Node()” recursively.
- Else,
- Call the function “make_Deletion()”.
- Check if the number is less than the node pointer value.
- Give function definition for “make_Deletion()”
- Create pointer named “tempPtr”.
- Check if the “nodePtr” is null.
- If the condition is true then, print “Cannot delete empty node.”
- Check if right node pointer is null.
- If the condition is true then,
- Make the node pointer as the temporary pointer.
- Reattach the left node child.
- Delete temporary pointer.
- If the condition is true then,
- Check is left node pointer is null
- If the condition is true then,
- Make the node pointer as the temporary pointer.
- Reattach the right node child.
- Delete temporary pointer.
- If the condition is true then,
- Else,
- Move right node to temporary pointer
- Reach to the end of left-Node using “while” condition.
- Assign left node pointer to temporary pointer.
- Reattach left node sub tree.
- Make node pointer as the temporary pointer.
- Reattach right node sub tree
- Delete temporary pointer.
- Give function definition for “display_InOrder()”.
- Check if the node pointer exists.
- Call the function “display_InOrder()” recursively.
- Print the value
- Call the function “display_InOrder()” recursively.
- Check if the node pointer exists.
- Give function definition for “display_PreOrder()”.
- Print the value.
- Call the function “display_PreOrder()” recursively.
- Call the function “display_PreOrder()” recursively.
- Give function definition for “display_PostOrder()”.
- Call the function “display_PostOrder()” recursively.
- Call the function “display_PostOrder()” recursively.
- Print value.
- Give function definition for assignment operator.
- Call the function “destroy_SubTree()”
- Call the copy constructor.
- Return the pointer.
- Copy tree function is called by copy constructor and assignment operator function
- Create a pointer named “newNode”.
- Check if “nPtr” is not equal to null
- Allocate memory dynamically.
- Assign pointer value to the new node.
- Call the function “copyTree()” by passing “nPtr” of left.
- Call the function “copyTree()” by passing “nPtr” of right
- Return the new node.
- Function definition for “setQueue()”.
- Check if the pointer “nodePtr” exists.
- Call the function “setQueue()” recursively by passing the left node.
- Call the function “setQueue()” recursively by passing the right node.
- Call the function “enqueue()” recursively by passing the left node.
Main.cpp:
- Include required header files.
- Inside “main()” function,
- Declare a variable “value” and assign it to 0.
- Create an object “intBT” for “IntBinaryTree” class.
- Insert 5 values using “insert_Node()” function.
- Display all the values by using the function “display_InOrder()”.
- Create an object “iqueue” for “DynIntQueue” class.
- Load the address to the pointer “qPtr”.
- Pass this pointer to the function “treeToQueue ()”.
- Do until the queue is not empty.
- Declare a variable.
- Call the function “dequeue()”.
- Display the value.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure. Alice's public key (n,public_key) is (247,7).
A code breaker manages to factories 247 = 13 x 19
Determine Alice's secret key.
To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.
Consider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.
Pllleasassseee ssiiirrrr soolveee thissssss questionnnnnnn
Chapter 21 Solutions
EBK STARTING OUT WITH C++
Ch. 21.1 - Prob. 21.1CPCh. 21.1 - Prob. 21.2CPCh. 21.1 - Prob. 21.3CPCh. 21.1 - Prob. 21.4CPCh. 21.1 - Prob. 21.5CPCh. 21.1 - Prob. 21.6CPCh. 21.2 - Prob. 21.7CPCh. 21.2 - Prob. 21.8CPCh. 21.2 - Prob. 21.9CPCh. 21.2 - Prob. 21.10CP
Ch. 21.2 - Prob. 21.11CPCh. 21.2 - Prob. 21.12CPCh. 21 - Prob. 1RQECh. 21 - Prob. 2RQECh. 21 - Prob. 3RQECh. 21 - Prob. 4RQECh. 21 - Prob. 5RQECh. 21 - Prob. 6RQECh. 21 - Prob. 7RQECh. 21 - Prob. 8RQECh. 21 - Prob. 9RQECh. 21 - Prob. 10RQECh. 21 - Prob. 11RQECh. 21 - Prob. 12RQECh. 21 - Prob. 13RQECh. 21 - Prob. 14RQECh. 21 - Prob. 15RQECh. 21 - Prob. 16RQECh. 21 - Prob. 17RQECh. 21 - Prob. 18RQECh. 21 - Prob. 19RQECh. 21 - Prob. 20RQECh. 21 - Prob. 21RQECh. 21 - Prob. 22RQECh. 21 - Prob. 23RQECh. 21 - Prob. 24RQECh. 21 - Prob. 25RQECh. 21 - Prob. 1PCCh. 21 - Prob. 2PCCh. 21 - Prob. 3PCCh. 21 - Prob. 4PCCh. 21 - Prob. 5PCCh. 21 - Prob. 6PCCh. 21 - Prob. 7PCCh. 21 - Prob. 8PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 4. def modify_data(x, my_list): X = X + 1 my_list.append(x) print(f"Inside the function: x = {x}, my_list = {my_list}") num = 5 numbers = [1, 2, 3] modify_data(num, numbers) print(f"Outside the function: num = {num}, my_list = {numbers}") Classe Classe that lin Thus, A pro is ref inter Ever dict The The output: Inside the function:? Outside the function:?arrow_forwardpython Tasks 5 • Task 1: Building a Library Management system. Write a Book class and a function to filter books by publication year. • Task 2: Create a Person class with name and age attributes, and calculate the average age of a list of people Task 3: Building a Movie Collection system. Each movie has a title, a genre, and a rating. Write a function to filter movies based on a minimum rating. ⚫ Task 4: Find Young Animals. Create an Animal class with name, species, and age attributes, and track the animals' ages to know which ones are still young. • Task 5(homework): In a store's inventory system, you want to apply discounts to products and filter those with prices above a specified amount. 27/04/1446arrow_forwardOf the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.arrow_forward
- Management Information Systemsarrow_forwardQ2/find the transfer function C/R for the system shown in the figure Re དarrow_forwardPlease original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinksarrow_forward
- Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinksarrow_forwardWhat is cloud computing and why do we use it? Give one of your friends with your answer.arrow_forwardWhat are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning