Results 1 to 2 of 2

Thread: how to get the sum of the link list and locate if it is in the list

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2004
    Location
    San Isidro
    Posts
    326

    how to get the sum of the link list and locate if it is in the list

    i have this as my code anyone to help me get the sum of the likned list and the the largerst value in the linked list....i have an error oputput

    Code:
    int sum(nd **head){
    
      nd *p;
      p=*head;
      while(p!=NULL)
      {
    
        p=p->next;
        return p->x+p->x;
      }
    }
    Code:
    int locate(nd **head,int num){
    
      nd *p;
      p=*head;
      while(p!=NULL)
      {
    
        p=p->next;
        if(num==p->x)
        return 1;
        else
        return 0;
      }
    }
    I want to learn more
    grace

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: how to get the sum of the link list and locate if it is in the list

    Learn more about what the return statement does and you'll know why it doesn't work.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width