Thread: how to deside the order of the parts..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    how to deside the order of the parts..

    I got this solution to the tree2list function.

    The 3rd part of this solution is going to the tail of the linked list.
    The 4th part is the linking part.

    I think its odd to go threw the list and then do the linking.

    I think we need to do the linking first (in order to have a list) and then go to the last member of the list.

    Code:
    node* tree2list(node*root) {
     node *head,*temp;
    
    if (!root) return NULL;
    head=tree2list(root->left);
    if (!head) return root;
    
    for(temp=head;temp->next;temp=temp->next){  //3rd part
    }
    
    temp->next=root;                                          //4th part
    root->next=tree2list(root->right);
    
    return head;
    
    }

  2. #2
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Is this a solution you have come up with yourself? You have a recursive search through the left branch of this tree, but how are you really going down the right side? Your Recursive function tree2list is exclusive for the left side branch unless I have overlooked something.

    Seems that some of this solution is missing. What is the intent of your for loop and and empty block for your third part?

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    my recursion is fine

    you can do a trace on a simple binary tree

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Your recursion doesn't look fine to me....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laplace Expansion
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 11:26 PM
  2. Embedded SQL Order By
    By cjohnman in forum C Programming
    Replies: 12
    Last Post: 04-15-2008, 03:45 PM
  3. Gradient fills
    By pronecracker in forum Windows Programming
    Replies: 5
    Last Post: 04-29-2007, 11:55 AM
  4. How do you order your game code?
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 02-05-2006, 06:26 PM
  5. what is the significance of low order and high order bits
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:46 AM