Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit de67899

Browse files
committed
Add custom class for min-heap in priority_queue
1 parent e8fa276 commit de67899

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ if (CMAKE_BUILD_TYPE MATCHES RELEASE)
77
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
88
endif (CMAKE_BUILD_TYPE MATCHES RELEASE)
99

10-
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp)
10+
set(SOURCE_FILES main.cpp Program.cpp Graph.cpp DirectedGraph.cpp UndirectedGraph.cpp MinHeapElement.cpp)
1111
add_executable(GraphRepresentationsAndAlgorithmsComparison ${SOURCE_FILES})

MinHeapElement.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Created by barto on 20.05.18.
3+
//
4+
5+
#include "MinHeapElement.h"
6+
7+
// MinHeapElement
8+
// public
9+
10+
MinHeapElement::MinHeapElement(int edgeBeginning, int edgeEnd, int edgeValue) {
11+
this->edgeBeginning = edgeBeginning;
12+
this->edgeEnd = edgeEnd;
13+
this->edgeValue = edgeValue;
14+
}
15+
16+
int MinHeapElement::getEdgeBeginning() const {
17+
return edgeBeginning;
18+
}
19+
20+
int MinHeapElement::getEdgeEnd() const {
21+
return edgeEnd;
22+
}
23+
24+
int MinHeapElement::getEdgeValue() const {
25+
return edgeValue;
26+
}
27+
28+
// MinHeapElementComparator
29+
// public
30+
31+
int MinHeapElementComparator::operator()(const MinHeapElement &element1, const MinHeapElement &element2) {
32+
return element1.getEdgeValue() > element2.getEdgeValue();
33+
}

MinHeapElement.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Created by barto on 20.05.18.
3+
//
4+
5+
#ifndef GRAPHREPRESENTATIONSANDALGORITHMSCOMPARISON_MINHEAPELEMENT_H
6+
#define GRAPHREPRESENTATIONSANDALGORITHMSCOMPARISON_MINHEAPELEMENT_H
7+
8+
9+
class MinHeapElement {
10+
public:
11+
MinHeapElement(int edgeBeginning, int edgeEnd, int edgeValue);
12+
13+
private:
14+
int edgeBeginning;
15+
int edgeEnd;
16+
int edgeValue;
17+
18+
public:
19+
int getEdgeBeginning() const;
20+
int getEdgeEnd() const;
21+
int getEdgeValue() const;
22+
23+
};
24+
25+
class MinHeapElementComparator {
26+
public:
27+
int operator() (const MinHeapElement& element1, const MinHeapElement& element2);
28+
29+
};
30+
31+
32+
#endif //GRAPHREPRESENTATIONSANDALGORITHMSCOMPARISON_MINHEAPELEMENT_H

0 commit comments

Comments
 (0)