Help with creating a Huffman Tree.

Can someone please help me with my implementation of a Huffman tree. I feel as though I'm going about this in the wrong way but I truly don't know where nor where start. I've been searching for a answer for awhile but I am not finding anything that helps. Here is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// tree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include<vector>
#include <queue>
using namespace std;

struct node
{
	char symbol;
	int freq;
	node *left,*right;
	node *next;  
	node *root;
};

int _tmain(int argc, _TCHAR* argv[])
{
	node *root;
    node *curr;
	
    root = new node;
    root->next = NULL;
	root->freq = count;
	root->left=NULL;
	root->right=NULL;

    curr = root;

	priority_queue<int>sortqueue;

	string foo = "Hello World";
	char *p = new char [foo.length()];
	memcpy(p,foo.c_str(), foo.length());


	for(int i = 0; i < foo.length(); i++)
	{
		char temp = p[i];
		int count = 1;

		for(int j=0; j<i; j++ )

			{
				if(p[i] == p[j])
				{
					i++;
				}
			}

		temp = p[i];


	for(int h=i+1; h<foo.length(); h++ )

		{
			if(p[i] == p[h])
			{
				count++;
			}
		}

	sortqueue.push(count);

	cout << temp;
	cout << count<<endl;

	
	/*cout << sortqueue.top() <<endl;
		sortqueue.pop();*/


	//node *q;
	//q->symbol=temp;
	//q->freq=count;
	//q->left=NULL;
	//q->right = NULL;
	//q->next = NULL;




	
	}
	return 0;
}

Topic archived. No new replies allowed.