Finish MaxHeap ctor, dtor and op=
This commit is contained in:
parent
4d917b2db8
commit
be91573abc
|
@ -23,8 +23,7 @@ int main()
|
|||
int choice = -1;
|
||||
int val;
|
||||
|
||||
while (!exit)
|
||||
{
|
||||
while (!exit) {
|
||||
std::cout << "##### Max Heap Menu #####\n\t0. Exit"
|
||||
"\n\t1. Insert\n\t2. Delete\n\t3. Print"
|
||||
<< "\n\t4. Empty\n\t5. Min\n\t6. Max\n";
|
||||
|
@ -55,11 +54,11 @@ int main()
|
|||
break;
|
||||
|
||||
case MIN:
|
||||
std::cout << "Min value within our tree: " << testList.findMin() << endl;
|
||||
std::cout << "Min value within our heap: " << testList.findMin() << std::endl;
|
||||
break;
|
||||
|
||||
case MAX:
|
||||
std::cout << "Max value within our tree: " << testList.findMax() << endl;
|
||||
std::cout << "Max value within our heap: " << testList.findMax() << std::endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -67,5 +66,5 @@ int main()
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,8 +24,12 @@ MaxHeap::MaxHeap() : size(0), index(0), heap(NULL) {}
|
|||
*
|
||||
* @param rhs
|
||||
*/
|
||||
MaxHeap::MaxHeap(const MaxHeap& rhs) : size(rhs.size), index(rhs.index), heap(rhs.heap)
|
||||
MaxHeap::MaxHeap(const MaxHeap& rhs) : size(rhs.size), index(rhs.index)
|
||||
{
|
||||
heap = new int[size];
|
||||
for (int i = 0; i < index; i++) {
|
||||
heap[i] = rhs.heap[i];
|
||||
}
|
||||
}
|
||||
|
||||
/** constructor
|
||||
|
@ -49,14 +53,18 @@ MaxHeap::~MaxHeap()
|
|||
}
|
||||
|
||||
/** operator=
|
||||
* Sets one heap equal to another, making the two refer to the same data
|
||||
* Sets one existing MaxHeap equal to another existing MaxHeap
|
||||
*
|
||||
* @param rhs An existing MaxHeap to set equal to
|
||||
* @return The MaxHeap object which we want to create a reference to
|
||||
* @param rhs An existing MaxHeap
|
||||
* @return The copied MaxHeap object
|
||||
*/
|
||||
const MaxHeap& MaxHeap::operator=(const MaxHeap& rhs)
|
||||
MaxHeap MaxHeap::operator=(MaxHeap rhs)
|
||||
{
|
||||
if (this == &rhs) return *this;
|
||||
std::swap(heap, rhs.heap);
|
||||
size = rhs.size;
|
||||
index = rhs.index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class MaxHeap {
|
|||
MaxHeap(const MaxHeap& rhs);
|
||||
MaxHeap(int _size);
|
||||
~MaxHeap();
|
||||
const MaxHeap& operator=(const MaxHeap& rhs);
|
||||
MaxHeap operator=(MaxHeap rhs);
|
||||
void insert(int val);
|
||||
void del();
|
||||
void print();
|
||||
|
|
Loading…
Reference in New Issue