Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Searching in linked list problem!

linked list

  • Please log in to reply
3 replies to this topic

#1 bexita

bexita

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 09 November 2011 - 05:44 AM

Hi,
I wanted to search an element (char) in the list S, but everytime it said that 02x is not in S
How to declare char input "target" in a manner way? i think the declaration is my mistake for this code. Im stucking on this. ^^


struct Node;typedef Node* NodePtr;
typedef void* VoidPtr;
typedef char* Ptr;
typedef int* Pi;
struct Node
{
    VoidPtr data;
    NodePtr next;
};


bool Search(NodePtr& head, VoidPtr& target)    
{
    bool found = false;
    
    NodePtr here = head;   
    
    while (here != NULL && !found) 
    {
        if (here->next ==target)
            found =true;
        else
            here = here ->next;
            return found;
    }
    
    
}




void Search_Menu (NodePtr& head)
{
    VoidPtr target;
    cout <<setw(70)<<setfill('=')<<endl;
    PrintList(head);
    
    cout <<"\nWhich element?: ";
    cin >>target;
    
    if((Search(head, target)==true))
    {
        cout <<target<<" is in S ."<<endl;
    }
    else
    {
        cout <<target <<" is not in S."<<endl;
    }
}


[/QUOTE]
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 November 2011 - 07:14 AM

You need to move "return found'" out of your while loop.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 bexita

bexita

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 09 November 2011 - 07:40 AM

Still error ,

I think the error comes from VoidPtr target , but i am not sure how to fix..
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 November 2011 - 08:39 AM

What is your input?
What is your output?
What is your expected output?
Where's the rest of your code? For example, I have no idea what data types you're dealing with.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: linked list

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download