Thread: Question[Urgent]

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    66

    Question[Urgent]

    Code:
     void add(struct node **root, int x)
     {
          struct node *conductor;
          if(*root==NULL)
          {
              (*root)=malloc(sizeof(struct node));
              (*root)->value=x;
              (*root)->next=NULL ;         
                        }
         else
         {
             conductor = *root;
             while(conductor->next!=NULL)
             {
                conductor = conductor -> next;             
                }                
             conductor->next=malloc(sizeof(struct node));
             conductor->next->value=x;
             conductor->next->next=NULL;
             } 
             
          }

    what does conductor = conductor -> next; means? i've trace the whole program already but I just don't understand that conductor = conductor -> next; this is the code that our proff gave us as a note . but It still confuses me
    Last edited by kyel_dai92; 03-28-2011 at 08:07 PM.

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    You know what a linked list is? That line traces the whole list to the last node.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    It could have easily been written
    Code:
    for (conductor = *root; conductor->next !=NULL; conductor = conductor->next) {
       /* do nothing */
    }
             conductor->next=malloc(sizeof(struct node));
             conductor->next->value=x;
             conductor->next->next=NULL;

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    What datatype is *conductor? What does conductor->next point to?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kyel_dai92 View Post
    Code:
     void add(struct node **root, int x)
     {
          struct node *conductor;
          if(*root==NULL)
          {
              (*root)=malloc(sizeof(struct node));
              (*root)->value=x;
              (*root)->next=NULL ;         
                        }
         else
         {
             conductor = *root;
             while(conductor->next!=NULL)
             {
                conductor = conductor -> next;             
                }                
             conductor->next=malloc(sizeof(struct node));
             conductor->next->value=x;
             conductor->next->next=NULL;
             } 
             
          }

    what does conductor = conductor -> next; means? i've trace the whole program already but I just don't understand that conductor = conductor -> next; this is the code that our proff gave us as a note . but It still confuses me
    Ok... 4 threads, 7 days, 10 helpers, over 100 messages.... and you STILL don't know what this is?

    WOW.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    66
    I just need clarification, I understand it already, I just need clarifications though.

    Quote Originally Posted by Subsonics View Post
    What datatype is *conductor? What does conductor->next point to?
    it's a pointer

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by kyel_dai92 View Post
    I just need clarification, I understand it already, I just need clarifications though.



    it's a pointer
    Yeah, it's a pointer to struct node, just like next. This means that the address in next can be assigned to conductor.

    So, when doing "conductor = conductor->next" you are effectively moving ahead in the list, one node at a time in each iteration of the loop.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kyel_dai92 View Post
    I just need clarification, I understand it already, I just need clarifications though.
    If you needed clarification then you didn't understand it.

    Either that or you're just playing for attention.

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    66
    can we just stay in topic here for peeps sake , I am just asking a question

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The topic is you, after having been directed to a very good tutorial on it, and having started four or more threads on linked lists, and after having easily a half a dozen people try to help you, still not understanding.

    Maybe programming just isn't your thing.


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

  11. #11
    Registered User
    Join Date
    Mar 2011
    Posts
    66
    I am just asking a question if you are not gonna say something good don't say it.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kyel_dai92 View Post
    I am just asking a question if you are not gonna say something good don't say it.
    Ok... then I am going to give you some of the best advice anyone here could give you...

    You are plainly not grasping programming concepts. I simply don't think you have it in you.
    You should drop the course and get into something you can get your head around.

    No matter what you decide... PLEASE stop wasting people's time repeatedly asking the same questions.
    If something is unclear, go back and re-read the threads you've started, revisit the tutorials, look in your textbooks... but do not ask to apply hundreds of cumulative man-hours repeately answering the same question.
    Last edited by CommonTater; 03-29-2011 at 07:30 AM.

Popular pages Recent additions subscribe to a feed