Ejemplo n.º 1
0
LinkedBinaryTree populatetree(LinkedBinaryTree :: Position p , LinkedBinaryTree myTree)
{
	LinkedBinaryTree::Position temp;
	temp  = p;
	
	
		if (i < n)
		{
			*temp = treeData[i]; //write data o node
			if (myTree.size()<n)
			{ 
				myTree.expandExternal(temp);
				myQueue.push(temp.left());
				myQueue.push(temp.right());
			}
			
			if (!myQueue.empty())
			{
				myQueue.pop(); //remove front of queue
				temp = myQueue.front(); // set iterator to front
				populatetree(temp, myTree);	//recursive call
			}
			
			
			i++; //increment count
		}
		else
		{
			return myTree;
		}
}
Ejemplo n.º 2
0
void buildTree(Position p) {                                 // This function aims to build a huffman tree
    if (stream.read() == 1) *p = stream.read(9);             // if a 1 is found, use the next 9 bits as a node
    else {
        huffman.expandExternal(p);                           // generates children
        buildTree(p.left());                                 // calls the build on the left child
        buildTree(p.right());                                // calls the build on the right child
    }
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
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;
}