Please use template <typename T>. This is a C++ Data Structures Question.
Code Screenshot
Code
// public function
void erase()
{
// root points to the root node of the tree
erase_util(this->root);
}
// MNode is the class that defines the node of the tree
// please change the name accordingly
void erase_util(MNode *node)
{
// if the tree is not empty
if(!node)
{
// traverse the left subtree
// getLeft() return pointer to left child
erase_util(node->getLeft());
// traverse the right subtree
// getLeft() return pointer to right child
erase_util(node->getRight());
// delete the current node
delete node;
}
}
Please use template <typename T>. This is a C++ Data Structures Question. Problem 5. (20 pts...
#ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO:: default constructor perform new to reserve memory of size INITIAL_CAPACITY. set num_items = 0; */ heap() { // write your code here }; /** Create a heap from a given array */ heap(dtype *other, size_t len) { // write your code here }; /** copy constructor copy another heap to this heap. */ heap(const heap<dtype> &other) { //write your code here }; /** Accessor...
v. 15 points) implementing data structure operations C++ code for a new public member function to be added to the doubly linked list data structure used in class. Return the average value of all elements in the list ple a list of integers) Throws a length error exception if the list is empty. template «typename E> E& 0; average You may use loops or recursion as needed. If necessary, you may add private helper function0s) The definition of the DLinkedList...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. The definition of the class for a binary tree (as a template) is given as follows: template < class T > class binTree { public: binTree ( ); // default constructor unsigned height ( ) const; // returns height of tree virtual void insert ( const T& ); //...
Create a template function printResult which prints a value of type T void printResult(T val); C++ Write a program to create two Mathematic type (template below) objects a(10, 5) and b(3.4, 5.5) which prints using the template function printResult the result of a.addition(), a.subtraction(), a.multiplciation(), a.division() b.addition(), b.subtraction(), b.multiplication(), b.division() (Template) template <typename T> class Mathematics{ private: T val1, val2; public: Mathematics(T v1, T v2) { val1 = v1; val2 = v2; } T addition() { return val1 + val2;...
Please use the linked approach implement the BST ADT, implement all the functions in the BSTree.cpp. Add the ouput of the implementation. use recursive functions to traverse the tree - read the implementation notes on using helper functions. Please use C++ programming ////////////////////////////////////////////////////////////// #include "BSTree.h" template <typename DataType, class KeyType> BSTree<DataType, KeyType>::BSTreeNode::BSTreeNode ( const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr ) { } template < typename DataType, class KeyType > BSTree<DataType, KeyType>::BSTree () { root = 0; } template...
Data Structures, algorithm, c++. Please explain if possible. Thank you! Complete the following function that returns the largest element of the binary tree rooted at root. template <typename T> T max (Node<T>root) if (root nullptr) return TO; T max1 = root->x; T max2 root->x; if (root->left != nullptr) maxlmax (root->left); if (root->right != nullptr) max2 max ( root->right); - if (root->x >= max1 && root->x >= max2) return __.-; if (max1 >= root->x && max1 >= max2) return-_-> return___--> Let...
#include <iostream> using namespace std; template <typename Item> class MyArray{ private: Item *myarray; int size; int used; void doubleSize(); public: MyArray(); ~MyArray(); int length(); void insertHead(Item i); void insertTail(Item i); void deleteHead(); void deleteTail(); void sortAscending(); void sortDescending(); Item operator [](int i){ return myarray[i]; } }; template <typename Item> MyArray<Item>::MyArray(){ size = 5; used = 0; myarray = new Item[size];...
Language:C++ only numbers 4 and 5 please 2. 1. Use the Node class from the slides to create a linked list of int's. Create a Node pointer called ptrHead that points to the head of the list. Make the list 5 nodes long. Generate random values to populate the list's data. All nodes should be in the heap. Add a function called addNodeFront that takes a pointer to the head of a list as an input parameter and that adds...
C++ ONLY PLEASE. CAN I GET SOME HELP WRITING THIS HEADER FILE? I MAINLY WANT TO KNOW HOW I WOULD WRITE IT WITH A TEMPLATE. PLEASE AND THANKS IN ADVANCE. **************LinkedList.h requirements************************ linked list Class EXTRA CREDIT OPPORTUNITY: Create the LinkedList class as a template class for 5 extra credit points!!! private memebers Create a structure called ListNode, which should hold a Dinosaur and a pointer to the next ListNode ListNode pointer called head – will eventually point to the...
(The SortedLinkedList class template) Complete the SortedLinkedList class template which is a doubly linked list and is implemented with a header node and a tail node. // SortedLinkedList.h // SortedLinkedList.h // A collection of data are stored in the list by ascending order #ifndef SORTEDLIST_H #define SORTEDLIST_H using namespace std; template <typename T> class SortedList { private: // The basic single linked list node type. // Nested inside of SortedList. struct NodeType { T data; NodeType* next; NodeType* prev; NodeType(const...