aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorymherklotz <ymherklotz@gmail.com>2016-12-09 22:32:32 +0000
committerymherklotz <ymherklotz@gmail.com>2016-12-09 22:32:32 +0000
commit6180812e7967ab37e0013c092c67a3c6bdcb7769 (patch)
treed0c2e71d3624ba3e726c9ad6c82a6e83ae68c542 /include
parentd8c53d9d9ba4f275db25c3a98c6e1b380b3c69e1 (diff)
downloadA-star-algorithm-6180812e7967ab37e0013c092c67a3c6bdcb7769.tar.gz
A-star-algorithm-6180812e7967ab37e0013c092c67a3c6bdcb7769.zip
fixed Node class and removed destructor
Diffstat (limited to 'include')
-rw-r--r--include/astar.hpp4
-rw-r--r--include/priority_queue.hpp14
2 files changed, 10 insertions, 8 deletions
diff --git a/include/astar.hpp b/include/astar.hpp
index c0eeee0..d40b97f 100644
--- a/include/astar.hpp
+++ b/include/astar.hpp
@@ -18,6 +18,10 @@ public:
// TODO These constructors have to change
Node();
+ void set_f(int i) {
+ f_score = i;
+ }
+
// overloading operators for ease of use.
friend bool operator<(const Node& n1, const Node& n2);
friend bool operator==(const Node& n1, const Node& n2);
diff --git a/include/priority_queue.hpp b/include/priority_queue.hpp
index f3b78ca..6fb4f54 100644
--- a/include/priority_queue.hpp
+++ b/include/priority_queue.hpp
@@ -36,14 +36,12 @@ template<typename T>
PriorityQueue<T>::PriorityQueue() : size(0), capacity(1) {
T *tmp_head = new T;
- std::cout << "constructor" << std::endl;
priority_array = tmp_head;
}
template<typename T>
PriorityQueue<T>::~PriorityQueue() {
- std::cout << "destructor" << std::endl;
delete[] priority_array;
}
@@ -57,8 +55,6 @@ void PriorityQueue<T>::push(const T& element) {
while(insert_loc < size && element > priority_array[insert_loc])
++insert_loc;
- size++;
-
insert_queue(element, insert_loc);
}
@@ -66,11 +62,9 @@ template<typename T>
T PriorityQueue<T>::pop() {
if(!size)
throw "Priority Queue is empty, no item to pop";
- else if(size - 1 == capacity / 2)
+ else if(size == capacity / 2)
resize_queue(0.5);
- size--;
-
return remove_queue(0);
}
@@ -90,7 +84,7 @@ template<typename T>
void PriorityQueue<T>::insert_queue(const T& element, const unsigned int& loc) {
T *tmp_array = new T[capacity];
- for(unsigned int i = 0; i < size; ++i)
+ for(unsigned int i = 0; i < size + 1; ++i)
if(i == loc)
tmp_array[i] = element;
else if(i < loc)
@@ -98,6 +92,8 @@ void PriorityQueue<T>::insert_queue(const T& element, const unsigned int& loc) {
else
tmp_array[i] = priority_array[i - 1];
+ size++;
+
delete[] priority_array;
priority_array = tmp_array;
}
@@ -116,6 +112,8 @@ T PriorityQueue<T>::remove_queue(const unsigned int& loc) {
else
tmp_array[i - 1] = priority_array[i];
+ size--;
+
delete[] priority_array;
priority_array = tmp_array;