need help ASAP ,

This is a discussion on need help ASAP , within the C Programming forums, part of the General Programming Boards category; well ,, here is a function i search for the Max GPA in a tree , where : Code: struct ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    14

    need help ASAP ,

    well ,,
    here is a function i search for the Max GPA in a tree , where :
    Code:
    struct treenode
    {
           int st_id;
           float gpa;
           ptrtotree left;
           ptrtotree right;
    };
    
    
    void MaxGPA(ptrtotree t,float max)         //here : float &max ?!!!
    {
         if(t!=NULL)
         {
                    if(t->gpa > max)
                    {
                                   max=t->gpa;
                    }
                    MaxGPA(t->left,max);
                    MaxGPA(t->right,max);
         }
    
    
    
    }
    
    // i am wondering how can i define the float max , or float *max ,
    
    void main
    {
        float max;

    need help ASAP
    thanks in advance

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    void MaxGPA(ptrtotree t,float max)         //here : float &max ?!!!
    This is c. It has to be
    Code:
    void MaxGPA(ptrtotree t,float * max)
    {
         if(t!=NULL)
         {
                    if(t->gpa > * max)
                    {
                                   *max=t->gpa;
                    }
                    MaxGPA(t->left,max);
                    MaxGPA(t->right,max);
         }
    }
    Kurt

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Is this a binary tree? As in, a tree where the left nodes are all less than the right nodes? Can you see the pointlessness of scanning the entire tree? Just find the rightmost child. By definition it will be the greatest.

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Ya, he could have put a if statment in main before calling MaxGPA function. Becuase, head node->gpa coule be < max or > max. If it is < then cleck only the left handside of the tree other wise the right handside of the tree.

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help ASAP....
    By Maxwell in forum C++ Programming
    Replies: 16
    Last Post: 09-14-2005, 06:56 PM
  2. Help Needed Please... Asap
    By Shabba in forum C Programming
    Replies: 2
    Last Post: 01-13-2004, 03:24 PM
  3. Strange characters in output Need Help ASAP
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2003, 05:35 PM
  4. Count_nums (need help ASAP!)
    By legacye in forum C Programming
    Replies: 6
    Last Post: 11-22-2003, 05:32 PM
  5. Help Needed Asap With Searching An Array!
    By HelpMe++ in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2003, 04:44 AM

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