Linked list search??

This is a discussion on Linked list search?? within the C Programming forums, part of the General Programming Boards category; I have accepted input into variable head->array[a]. I now have to search the linked list to see if the input ...

  1. #1
    ren
    ren is offline
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Linked list search??

    I have accepted input into variable head->array[a]. I now have to search the linked list to see if the input in array[a] is already stored. I have been trying to convert a linked list search from C++ but have not been successful can anyone please help me?

    This is what I have:

    head->array[a]==target;
    previous=NULL;
    current=head;

    while (current !=NULL && (*current) !=target)
    {
    previous=current;
    current=*current->next;
    }

    if ((current !=NULL) && ((*current) == target))
    printf("your data has already been entered");

  2. #2
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up

    head->array[a]==target;
    I guess that was ur problem...

    say...

    head->array[a]=target;


    if ((current !=NULL) && ((*current) == target))
    printf("your data has already been entered");
    if(*current ==target)
    printf("your data has already been entered");
    else
    --------- /* data not entered. do what ever u want to. */

    Regards.
    Sriharsha.
    Help everyone you can

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    struct node *search ( struct node *list, Item key, int searchIndex )
    {
      while ( list != NULL && list->array[searchIndex] != key )
        list = list->next;
      return list;
    }
    -Prelude
    My best code is written with the delete key.

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, 07:16 PM
  2. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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