problem linked list?

This is a discussion on problem linked list? within the C++ Programming forums, part of the General Programming Boards category; 2006-01-20 : 22:40 -Edit- -Reply- -Top- linked List? Updated by asif on 2006-01-20 22:41 -------------------------------------------------------------------------------- Hi dear, I have a ...

  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
    21,632
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 01:45 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 05:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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