|
|
@@ -68,14 +68,25 @@ void PriorityQueue::removeKey(int index){
|
|
|
}
|
|
|
|
|
|
void PriorityQueue::change(int *key, int *newK){
|
|
|
- if (heapArray[*key] == NULL) {
|
|
|
- std::cout << "PriorityQueue::change key " << *key << " not found" << std::endl;
|
|
|
- return;
|
|
|
+// needs to change. I'm looking for the key, not the index?
|
|
|
+ for (int i = 0; i >= heap_size; i++) {
|
|
|
+ if (heapArray[i] == *key) {
|
|
|
+ // if the key is found exchange the old key for the new
|
|
|
+ heapArray[i] == *newK;
|
|
|
+
|
|
|
+ // figure out the case when heapify up/down are needed
|
|
|
+ if (*key > *newK) {
|
|
|
+ heapifyUp(i);
|
|
|
+ } else if (*key < *newK) {
|
|
|
+ heapifyDown(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ std::cout << "PriorityQueue::change key " << *key << " not found" << std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- int temp = *key;
|
|
|
- *key = *newK;
|
|
|
- *newK = temp;
|
|
|
}
|
|
|
|
|
|
void PriorityQueue::heapifyDown(int node){
|