#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 functions */
/** returns the root of the heap */
dtype &root();
/** returns the left child of the given node. */
size_t left(size_t index);
/** returns the right child of the given node. */
size_t right(size_t index);
/** returns the parent of the given node. */
size_t parent(size_t index);
/** returns num_items of the array */
size_t size();
/** Core heap operations */
/** perform heapify operation over the array. */
void heapify(size_t index);
/** create a heap from the given input. */
void build_heap();
/** heap sort
create a copy darray to sorted_array.
then perform heapsort over sorted_array.
*/
void heapsort();
/* insert items into heap */
void insert(const dtype &key);
/* remove items from the heap*/
void remove();
/** print heap **/
void print(std::string name);
private:
static const size_t INITIAL_CAPACITY;
size_t num_items;
dtype *darray;
dtype *sorted_array;
}; //end of class heap
template<typename dtype>
const size_t heap<dtype>::INITIAL_CAPACITY = 100;
}
/** TO DO : implement all the member functions here.
} //end of namespace
**/
#endif

![if (v.size 0) throw runtime_error (Heap is empty) T removedElement = v[0]; v[0] = v[v . size ( ) -1]; v.pop backO int curre](http://img.homeworklib.com/questions/9a95f3f0-4616-11eb-ad0d-0d9adbd8a372.png?x-oss-process=image/resize,w_560)

#ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO::...
Given the following code: #ifndef TREE_H #define TREE_H #include <iostream> #include "TreeNode.h" template< typename NODETYPE > class Tree { public: Tree() : rootPtr( nullptr ) {} void insertNode( const NODETYPE &value ) { insertNodeHelper( &rootPtr, value ); } void preOrderTraversal() const { preOrderHelper( rootPtr ); } void inOrderTraversal() const { inOrderHelper( rootPtr ); } private: TreeNode< NODETYPE > *rootPtr; void insertNodeHelper( TreeNode< NODETYPE > **ptr, const NODETYPE &value ) { if ( *ptr == nullptr ) * ptr = new...
Please show me how to overload the operators << and >> #ifndef LINK_LIST #define LINK_LIST #include <iostream> using namespace std; template <typename T> struct Int_Node { T value; Int_Node<T> *pre, *next; }; template <typename T> class Link_List { template <typename U> friend ostream &operator<<(ostream &, const Link_List<U> &);// print all integers in the list template <typename U> friend istream &operator>>(istream &, Link_List<U> &);// input a value at the back of the list, like insert_node(val);...
#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];...
vector.h: #ifndef VECTOR_H #define VECTOR_H #include <algorithm> #include <iostream> #include <cassert> template <typename T> class Vector { public: Vector( int initsize = 0 ) : theSize( initsize ), theCapacity( initsize + SPARE_CAPACITY ) { objects = new T[ theCapacity ]; } Vector( const Vector & rhs ) : theSize( rhs.theSize), theCapacity( rhs.theCapacity ), objects( 0 ) { objects = new T[ theCapacity ]; for( int k = 0; k < theSize; ++k) objects[ k ] = rhs.objects[ k...
#include<iostream>
using namespace std;
class TNode
{
public:
int val;
TNode(){}
TNode(int v){val = v;}
TNode * left;
TNode * right;
TNode * parent;
};
class BTree
{
public:
//constructors and destructor
BTree();
BTree(TNode *r);// initialize BTree with the root r. r is the
only node.
BTree(const BTree & t); // copy constructor
BTree(const int *p, const int n);// similar to the copy
constructor, but your input is of the array form.
// input is given an array that denotes...
Implement the class MaxHeapPriorityQueue as a heap with the following operations: • MaxHeapPriorityQueue() creates a new heap that is empty. It needs no parameters and returns nothing. Note that as discussed in the video lecture, the index range of the array implementation of a heap is 1:n, NOT 0:n-1 • parent(index) returns the value of the parent of heap[index]. index is between 1 and the size of the heap. If index<=1 or index>size of the heap, it returns None •...
#ifndef RADIXSORT #define RADIXSORT #include<vector> // Function to get maximum value in array a[]. template <typename dataType> int getmax(dataType a[], int n) { int max = a[0]; for (int x = 1; x < n; x++) if (a[x] > max) max = a[x]; return max; } // Function to do counting sort according to significant digits repesented by // exp (where exp is 10^i). template <typename dataType> void CountSort(dataType a[], int n, int exp) { vector <int> result(n); int i,...
PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....
This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to List.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done. /** @pre assumes position is valid, if position is > item_count_ it returns an empty List, also assumes that operators <= and >= are defined...
// Header code for stack // requesting to create source code using C++ #ifndef Stack_h #define Stack_h #include <stdio.h> #include <string> #include <iostream> using namespace std; class Stack { public: Stack(); ~Stack(); bool empty(); string top(); void push(const string &val); void pop(); void display(ostream &out); private: class Node { public: string word; Node *next; }; Node *tos; }; #endif Header file provided above. PLS create source code for functions declared in the header. If changes are need no make in...