Thread: Help on linklist in a binary_tree

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    11

    Question Help on linklist in a binary_tree

    Code:
    struct Record
            {
             char own_name[20];
             int score_own;
             char opp_name[20];   
              int score_opp;
             char result[2];
             int wins;
             int losses;
              int ties;
             struct Record *next;
            };
    struct Team 
    	{ char team_name[20];
             struct Record record_link;
              struct Team *left;
              struct Team *right;
              struct Team *top;
    	}root;
    I have above two structures, The structure Team have an structure Record included. Stucture Team is an binary Tree. For every node in Structure Team of record_link, is a link_list.

    When I linking the code I found:
    root->record_link=root->record_link->next is not correct.

    So my question is how to visit the data of record_link through the tree?

    For example:
    Code:
          while(root->record_link->next!=NULL)
    	 {
             fprintf(fp2,"%s %d-%d %s\n",root->record_link.result,root- >record_link.score_own,root->record_link.score_opp,root->record_link.opp_name);
           root->record_link=root->record_link->next;
    }
    is not valid. How to visit each member of their value?

    Thanks

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You're including a record in team as a struct, not a pointer to struct. So you could do something like this:
    Code:
    root.record_link
    and
    Code:
    root.record_link->next
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Can I use while(root.record_link!=NULL) to judge whether the root.record is NULL or not?

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Not unless you define record_link as a pointer to struct instead of just a struct.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LinkList in C
    By $l4xklynx in forum C Programming
    Replies: 10
    Last Post: 12-04-2008, 03:18 AM
  2. help with reversing something in a linklist
    By Axel in forum C Programming
    Replies: 43
    Last Post: 10-23-2005, 07:14 AM
  3. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  4. MergeSort implementation with linklist.
    By Kam in forum C Programming
    Replies: 3
    Last Post: 10-21-2002, 11:04 AM
  5. Quick LinkList Help!!adding at the End
    By simly01 in forum C++ Programming
    Replies: 13
    Last Post: 07-28-2002, 07:19 AM