Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions MaxHeapVector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "MaxHeapVector.h"

MaxHeapVector::MaxHeapVector()
{

}

MaxHeapVector::~MaxHeapVector()
{

}

bool MaxHeapVector::isEmpty() const
{
return maxHeapVector.empty();
}

int MaxHeapVector::size()
{
int size = 0;
for (std::vector<int>::iterator it = maxHeapVector.begin(); it != maxHeapVector.end(); it++)
{
size++;
}
return size;
}

void MaxHeapVector::insert(const int x)
{
maxHeapVector.emplace_back(x);
}

const int MaxHeapVector::findMax() const
{
int maxVal = 0;
if (isEmpty())
return -1;
else
{
for (auto it = maxHeapVector.begin(); it != maxHeapVector.end(); it++)
{
if (*it > maxVal)
maxVal = *it;
}
return maxVal;
}
}

int MaxHeapVector::deleteMax()
{
int maxVal = 0;

std::vector<int>::iterator maxValPos = maxHeapVector.begin();

if (isEmpty())
return -1;
else
{
for (std::vector<int>::iterator it = maxHeapVector.begin(); it != maxHeapVector.end(); it++)
{
if (*it > maxVal)
{
maxVal = *it;
maxValPos = it;
}
}
maxHeapVector.erase(maxValPos);

return maxVal;
}
}
18 changes: 18 additions & 0 deletions MaxHeapVector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "MaxHeap.H"
#include <vector>

class MaxHeapVector : public MaxHeap
{
public:
MaxHeapVector();
virtual ~MaxHeapVector();
bool isEmpty() const override;
int size() override;
void insert(const int x) override;
const int findMax() const override;
int deleteMax() override;
private:
std::vector<int> maxHeapVector;
};
23 changes: 23 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "MaxHeapVector.h"
#include <iostream>

int main()
{
MaxHeapVector bigV;

bigV.insert(1);
bigV.insert(2);
bigV.insert(3);
bigV.insert(4);
bigV.insert(5);
bigV.insert(6);
bigV.insert(1);

std::cout << "Max: " << bigV.findMax() << std::endl;
std::cout << "Is empty" << bigV.isEmpty() << std::endl;
std::cout << "Size: " << bigV.size() << std::endl;
bigV.deleteMax();
std::cout << "Max: " << bigV.findMax() << std::endl;
std::cout << "Is empty" << bigV.isEmpty() << std::endl;
std::cout << "Size: " << bigV.size() << std::endl;
}