Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do youinsert a tree into a heap????

Status
Not open for further replies.

randy4126

Programmer
Jun 2, 2001
62
US
I need help Im trying to implement the huffman algorithm.
And i am running into a problem that I need to insert a tree into the heap and i think becuse i told it only a node it cuts off my branches.

this is what im doing...

struct TreeNode
{
int Weight;
char Letter;
TreeNode *RightChild;
TreeNode *LeftChild;
};

/* Implementation of HEAP ADT */


class Heap
{
public:
Heap(): v( 1 ), Size( 0 ){}; //don't use first one
void insert(TreeNode *x);
TreeNode* findMin( ) const;
void deleteMin( );
bool isEmpty() const;
int Size; // Number of elements in heap

private:

vector<TreeNode *> v ; // The heap vector
void perculateDown (int loc);
void perculateUp (int loc);
};
Randy
smiletiniest.gif


You can Email me at: RCooper@cinci.rr.com
 
By flattening the tree, using a pre-post-inorder traversal. You could probably use some extra indicators that would help you reconstruct the tree, such as depth of the node. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
thanks i found my problem it ended up being a problem in my remove heap routine. Thanks Randy
smiletiniest.gif


You can Email me at: RCooper@cinci.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top