Thread: problem linked list?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    problem linked list?

    2006-01-20 : 22:40 -Edit- -Reply- -Top- linked List?
    Updated by asif on 2006-01-20 22:41

    --------------------------------------------------------------------------------

    Hi dear,

    I have a list of linked list of element like below.the last item of the list points back to one of the item of the list.

    O---> |A|---> |B|--->|C|--->|D|

    Here, O represnt of Head
    so, My question is the function what returns the number of items in linked-list of the above type.


    another question is same but here list is much longer than above.

    I tried like
    Int getNumberOfItems( void *listHead ) {
    int data;
    node next;

    head =malloc(sizeof(void *listhead));
    second =malloc(sizeof(void *listhead));
    thrird =malloc(sizeof(void *listhead));
    fourht=malloc(sizeof(void *listhead));

    head->data=A
    head->next=second

    head->data=B
    head->next=third

    head->data=C
    head->next=fourth

    head->data=D
    head->next="Here i dont know where it will reference"

    and what will return this function?

    Please give me answers of both questions diffrently.

    Waiting for positive reply.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please give me answers of both questions diffrently.
    Sounds like you're trying to get the answers to your homework questions done for you by posting at more than one messageboard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    In your code you are just changing the head's Next pointer to point to the second then third then fourth nodes.
    What you need to do is have a pointer which moves thru the list like this
    Code:
    while (Pointer->Next!=NULL)
    {
       NumberOfNodes++;
       Pointer=Pointer->Next;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM