int main() { huffman.addRoot(); // put a root on our tree Position position = huffman.root(); // set our position "iterator" at huffman's root cout << "Name of file: "; cin >> file; stream.open(file); buildTree(position); // build the huffman tree while (!stream.eof()){ // before the end of the input character=decode(huffman.root()); // decode the tree if (character!='#') // before the EOF character message+=character; // append the decoded character to the message else { while (!stream.eof()){ stream.read(); } } } cout << message << endl; return 0; }
LinkedBinaryTree ingestTree(LinkedBinaryTree m) { LinkedBinaryTree::Position temp; queue<LinkedBinaryTree::Position>tempQueue; if (m.empty()) { m.addRoot(); } temp = m.root(); int treeDepth = 0; for (int j = 0; j < n; j++) { tempQueue.push(temp); *temp = treeData[j]; cout << "Node" << *temp << ":\t"<< j << "th operation, current tree size: " << m.size() << endl; if (m.size() < n) { m.expandExternal(temp);//expand node of tree tempQueue.push(temp.left()); // push left child to queue tempQueue.push(temp.right()); // push right child to queue } tempQueue.pop();// remove processed node from queue temp = tempQueue.front(); // set current node to front of queue treeDepth = log2(m.size());// track depth of tree } cout << "current tree size: " << m.size() << endl; cout << "current tree Depth: " << treeDepth << endl; return m; }
int main() { clock_t time; time = clock(); LinkedBinaryTree myTree; myTree.addRoot(); LinkedBinaryTree::Position myPosition; myPosition = myTree.root(); vector <int> myVector(100); /* Iterative Input*/ myTree = ingestTree( myTree); cout << myTree.size() << endl; time = time - clock(); cout << "\n Program Execution Time:" << (time / CLOCKS_PER_SEC) << endl; system("pause"); return EXIT_SUCCESS; }