소스 검색

added heapsort to makefile and added json traversal to heapsort

Natalie Pueyo 8 년 전
부모
커밋
554dc9d760
3개의 변경된 파일24개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 1
      program2/Makefile
  2. 16 0
      program2/heapsort.cxx
  3. 1 1
      program2/priorityqueue.cpp

+ 7 - 1
program2/Makefile

@@ -13,13 +13,16 @@ CREATE_DATA_EXE=$(CREATE_DATA_SRC:.cxx=.exe)
 TEST_DATA_SRC=testCode.cxx
 TEST_DATA_EXE=$(TEST_DATA_SRC:.cxx=.exe)
 
+HEAP_DATA_SRC=heapsort.cxx
+HEAP_DATA_EXE=$(HEAP_DATA_SRC:.cxx=.exe)
+
 PRIORITY_SOURCES=priorityqueue.cpp
 PRIORITY_HEADERS=$(PRIORITY_SOURCES:.cpp=.h)
 PRIORITY_DEV_OBJ=$(PRIORITY_SOURCES:.cpp=.o)
 PRIORITY_OPT_OBJ=$(PRIORITY_SOURCES:.cpp=.o3)
 
 .PHONY: all
-all: priority_cla $(CREATE_DATA_EXE) $(TEST_DATA_EXE)
+all: priority_cla $(CREATE_DATA_EXE) $(TEST_DATA_EXE) $(HEAP_DATA_EXE)
 
 # Priority Queue
 .PHONY: $(PRIORITY_CLA)
@@ -39,6 +42,9 @@ $(PRIORITY_OPT_OBJ): %.o3: %.cpp %.h
 $(TEST_DATA_EXE): %.exe: %.cxx $(PRIORITY_OPT_OBJ)
 	$(CC) $(OPT) $^ -o $@
 
+# test code executable
+$(HEAP_DATA_EXE): %.exe: %.cxx $(PRIORITY_OPT_OBJ)
+	$(CC) $(OPT) $^ -o $@
 
 # Build
 .PHONY: clean

+ 16 - 0
program2/heapsort.cxx

@@ -5,6 +5,7 @@
 #include <sstream>
 
 #include "json.hpp"
+#include "priorityqueue.h"
 
 int main(int argc, char** argv) {
   // read JSON file and store in jsonObject
@@ -18,4 +19,19 @@ int main(int argc, char** argv) {
 
   std::string sampleName;     // Sample key name to iterate
   nlohmann::json outputJSON;  // output JSON file
+  //int currValue = 0;          // current key value
+
+  int n = jsonObject["metadata"]["arraySize"];
+
+  class PriorityQueue sampleHeap;
+  sampleHeap.initiateHeap(n);
+
+  for (auto itr = jsonObject.begin(); itr != jsonObject.end(); ++itr) {
+    if (sampleName != "metadata") {
+      for (auto arrayItr = jsonObject[sampleName].begin(); arrayItr != jsonObject[sampleName].end(); ++arrayItr) {
+      }
+    }
+  }
+  std::cout << outputJSON << std::endl;
+  file.close();
 }

+ 1 - 1
program2/priorityqueue.cpp

@@ -30,6 +30,7 @@ void PriorityQueue::initiateHeap(int capacity){
     heap_size = 0;
     max_size = capacity;
     heapArray = new int[max_size];
+    //std::vector<int>* insArray = new std::vector<int>();
 }
 
 void PriorityQueue::insert(int key){
@@ -115,7 +116,6 @@ void PriorityQueue::heapifyDown(int index){
 void PriorityQueue::heapifyUp(int key, int index){
   int curIndex = index;
   int parentIndex = (curIndex)/2;
-  //heap_size++;
   // insert new key into the end of the array
   heapArray[curIndex] = key;