binary tree problem

This is a discussion on binary tree problem within the C Programming forums, part of the General Programming Boards category; i want to obtain the binary code of all the leafes of a bin tree. have any ideea on how ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    binary tree problem

    i want to obtain the binary code of all the leafes of a bin tree. have any ideea on how to do that?

    i code 0 for left and 1 of right.
    Thank you!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    00111010111011101010010101010010101001010010101010 10101000110011101001010101001010100101010101001010 10100101110101010101010100100101010101010101010010 10101001010110101101101011011101010001001010101010 10110101010101010101010111101010111100101010101010 10110000101000010100101111101011010101000010101011 11101011110100010110101010101011101011011101101100 10110110100001001011110110100101010100100110111010 10101101010


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    thank you. but i was thinking more of an algorithm on how to code that!

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    please... any ideea? i'm trying to implement huffman algorithm!

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    solved it... i can do a preorder tranversal:
    Code:
    void preordine(tree a,char bin[100])
    {
            char s[100],d[100];
            if((a->leg[0]==NULL)&&(a->leg[1]==NULL))
            {
                    printf("%lf\n",a->prob);
                    puts(bin);
            }
            else
            {
                    strcpy(s,bin);
                    strcpy(d,bin);
                    strcat(s,"0");
                    strcat(d,"1");
                    preordine(a->leg[0],s);
                    preordine(a->leg[1],d);
            }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem while making a binary tree
    By fancy217 in forum C Programming
    Replies: 8
    Last Post: 07-16-2008, 06:56 PM
  2. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 02:02 PM
  3. problem in storing data in a binary search tree
    By alavardi in forum C Programming
    Replies: 5
    Last Post: 02-13-2005, 03:20 PM
  4. Tree Problem
    By recluse in forum C Programming
    Replies: 36
    Last Post: 12-04-2004, 03:06 PM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21