Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 21, Problem 25RQE
Program Plan Intro
Binary tree:
- It is a tree data structure which comes under hierarchical data structure.
- It is made of nodes that have a left child, right child and a data element.
Tree traversal:
- There are 3 common methods
- Inorder traversal
- Preorder traversal
- Postorder traversal
- In inorder traversal, the left subtree is encountered first, then data node and then the right subtree.
- In preorder traversal, the data node is encountered first, then left subtree and then the right subtree.
- In postorder traversal, the left subtree is encountered first, then right subtree and then the data node.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Double pointers: Describe how this operation can be done in O(1) time if there are pointers in each node to both the previous and the next node.
typedef struct node{int data;struct node *left,*right;}BST;The node structure of BST is shown above. Please design an efficient algorithm to return the maximum keyword value in BST. Completion function: int findmax (BST *T)
struct node{
int a;
struct node * nextptr;
};
Write two functions. One for inserting new values to a link list that uses the given node structure.
void insert(struct node **head, int value);
Second function is called to count the number of even numbers in the link list. It returns an integer that represents the number of even numbers.
int countEvenNumbers(struct node *head);
Write a C program that reads a number of integers from the user and insert those integers into a link list (use insert function). Later pass the head pointer of this link list to a function called countEvenNumbers. This function counts and returns the number of even numbers in the list. The returned value will be printed on the screen.
Note 1: Do not modify the function prototypes.
Sample Input1:
Sample Output1:
45 23 44 12 37 98 33 35 -1
3
Sample Input2:
Sample Output2:
11 33 44 21 22 99 123 122 124 77 -1
4
Chapter 21 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
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
- data structers c languagearrow_forwardC++ URGENTTT preorder print traversalarrow_forward2-) In a double linked list, the structure of a node is defined as follows: struct node { int employeeNo; char name[20]; struct node *next; structnode *prev; }node; the nodes in the list are sorted according to employeeNo in ascending order (from smaller to larger ). Write a function to insert a node with a given name and employeeNo into the list so that the list will remain the sorted. employeeNo değerine göre kiüçükten büyüğe sıralanmış bir çift bağlı liste olsun. Verilen bir isim ve employeeNo değerine sahip düğümü listeye sıra bozulmayacak şekilde ekleyen bir fonksyion yazınız.arrow_forward
- struct remove_from_front_of_dll { // Function takes no parameters, removes the book at the front of a doubly // linked list, and returns nothing. void operator()(const Book& unused) { //// TO-DO (13) |||| // Write the lines of code to remove the book at the front of "my_dll", // // Remember, attempting to remove an element from an empty data structure is // a logic error. Include code to avoid that. ///// END-TO-DO (13) //// } std::list& my_dll; };arrow_forward1 Singly Linked List A linked list is a data structure where elements are connected to form a chain where each node points to the next one in the order. Exercise: Given the code of the Node struct, implement a singly linked list with the following functionalities: • addFront: add an integer key to the front of the list. • remove: deletes the smallest number larger than or equal the passed integer and returns the deleted value. If no number is found, returns -1. All cases must be handled. You can define any helper method as needed. #include #include #define INF INT_MAX // indicates infinity value using namespace std; struct Node int key; Node next; Node(int key) { this->key - key; this->next- NULL; }; class SinglyLinkedList public: SinglyLinkedList () head - NULL; void addFront (Node* node) 1 int remove(int val) { private: Node head; }; int main() { SinglyLinkedList sLL - neu SinglyLinkedList (); Node* nodel = new Node (5); Node node2 - neu Node (13); Node node3 - nev Node(7);…arrow_forward2-) In a double linked list, the structure of a node is defined as follows: struct node { int employeeNo; char name[20]: struct node *next; structnode *prev; }node; the nodes in the list are sorted according to employeeNo in ascending order (from smaller to larger ). Write a function to insert a node with a given name and employeeNo into the list so that the list will remain the sorted. employeeNo değerine göre kiüçüikten büyüğe sıralanmış bir çift bağlı liste olsun. Verilen bir isim ve employeeNo değerine sahip düğümü listeye sıra bozulmayacak şekilde ekleyen bir fonksyion yazınız.arrow_forward
- C Programming language Part 1: You need to define a data structure for a doubly linked list and a binary search tree. Also, you need to implement the following functions: Insert Sorted LINKEDLIST insertSorted(LINKEDLIST head, int num): head points to the first node in the sorted linked list; num is a number to be inserted in in correct place in the linked list pointed at “head”. The linked list should be sorted after inserting “num”. This function returns the head of the modified head. BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree. Find an element LINKEDLIST find(LINKEDLIST head,int num): head points to the first node of a linked list; num is a number to be searched for in the linked list started at “head”. This function returns a pointer to the node containing “num” or NULL if num is not found BSTREE find(BSTREE root,int…arrow_forwardDescribe the events that occur during a postorder traversal.arrow_forwardGraphs: Depth First Traversal Starting with the same graph program as last assignment, implement a depth first traversal method. Test iy on nodes 1, 2, and 3 as start nodes. Graph program: #include <iostream>#include <vector>#include <string>using namespace std; class Edge;//-------------------------------------------------------------////class Node{public:Node(string iname){name = iname;}string name;int in_count = 0;bool visited = false; vector<Edge *> out_edge_list;};//-------------------------------------------------------------////class Edge{public:Edge(string iname, double iweight, Node *ifrom, Node *ito){name = iname;weight = iweight;from = ifrom;to = ito;} string name;double weight;Node *from;Node *to;bool visited = false;}; //-------------------------------------------------------------////class Graph{public:vector<Node *> node_list;vector<Edge *> edge_list; //----------------------------------------------------------//Node*…arrow_forward
- Com Please solve in Dart Programming Language Traverse a collection with help of an iterator or list type object Use a Queue as collection and also use the move next function to traverse Solve it in the Dart. and don't forget to add the output otherwise I willl downvote the solutionarrow_forwardjava data structurearrow_forwardThis function should delete the first node if RemoveID is at the first node and contains two pointers in which helps removes any node and reroute. What is wrong with the code? void remove(node *&first, int RemoveID) { node *prev = NULL; node *temp; temp = first; cout << "Enter ID that you want to delete" << endl; cin >> RemoveID; while (temp->ID != RemoveID) { prev = temp; temp = temp->next; if (first == NULL) { cout << "No lists" << endl; return; } else if (first->ID == RemoveID) { node *temp = first; first = first->next; delete temp; } } }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education