소스 검색

couple small syntax fixes for source2, added a test for source2. seems to work

tarfeef101 7 년 전
부모
커밋
e539317394
3개의 변경된 파일40개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 3
      source2.h
  2. 36 0
      test2.cc
  3. BIN
      testfile2

+ 4 - 3
source2.h

@@ -1,6 +1,7 @@
 #ifndef __source1_H__
 #define __source1_H__
 #include <iostream>
+#include <vector>
 using namespace std;
 class Triehard2 // compressed binary trie
 // constructor should make a left and right that are empty for search to work
@@ -172,7 +173,7 @@ class Triehard2 // compressed binary trie
 		}*/
 		
 		// build an array of what is "processed" so far. then when a flag is hit, print that array.
-		void mainPrint(Trienode * curnode, vector<int> * chars, int right)
+		void mainPrint(Trienode2 * curnode, vector<int> * chars, int right)
 		{
 			if (!curnode) return;
 			int curmag = curnode->getMag();
@@ -486,7 +487,7 @@ class Triehard2 // compressed binary trie
 			}
 			else
 			{
-				Trienode * newnode = new Trienode(0, curnode->getCount()); // this is our new node, which should retain old flagging
+				Trienode2 * newnode = new Trienode2(0, curnode->getCount()); // this is our new node, which should retain old flagging
 				curnode->setCount(1); // curnode will now end where we want to insert, so this should be true
 				
 				while (curmag) // fills newnode with the extra magnitude
@@ -647,7 +648,7 @@ class Triehard2 // compressed binary trie
 			}
 			
 			curnode->subCount(); // Normally this is all that is necessary
-			if (curnode->getCount) return; // This means we aren't removing a node, so no compression is possible
+			if (curnode->getCount()) return; // This means we aren't removing a node, so no compression is possible
 			
 			// Cases where nodes have to be removed/compressed
 			if (!(curnode->getLeft()) && !(curnode->getRight())) // if our node has no children, destroy it and change parent's reference to NULL

+ 36 - 0
test2.cc

@@ -0,0 +1,36 @@
+#include "source2.h"
+#include <iostream>
+using namespace std;
+
+int main()
+{
+	Triehard2 * test = new Triehard2();
+	cout << "success! Created test" << endl;
+	int x[3] = {0,1,0};
+	int y[5] = {1,0,1,1,0};
+	int z[1] = {0};
+	int a[7] = {1,0,1,1,0,0,0};
+	int b[7] = {0,1,1,0,0,1,1};
+	test->insert(x, 3);
+	cout << "success! inserted x" << endl;
+	test->insert(a, 7);
+	cout << "success! inserted a" << endl;
+	test->insert(y, 5);
+	cout << "success! inserted y" << endl;
+	test->insert(y, 5);
+	cout << "success! inserted y" << endl;
+	test->insert(y, 5);
+	cout << "success! inserted y" << endl;
+	test->insert(z, 1);
+	cout << "success! inserted z" << endl;
+	test->insert(b, 7);
+	cout << "success! inserted b" << endl;
+	test->myPrintIsBetterThanYoursLogan();
+	cout << "Print Done!" << endl;
+	test->cut(y, 5);
+	cout << "success! cut y" << endl;
+	test->myPrintIsBetterThanYoursLogan();
+	delete test;
+	cout << "success! Completed test" << endl;
+	//while(1);
+}

BIN
testfile2