i have problem with my code to search node in link list. can anybody help me? sorry for my english..

        node *temp1;                            // create a temporary node
        temp1 = (node*)malloc(sizeof(node));    // allocate space for node
        temp1 = head;                         // transfer the address of 'head' to 'temp1'
        bool find = false;

        cout<<"ENTER THE VALUE:";
        cin>>info;                             // take value

        while (temp1!= NULL)
        {
              if (temp1->data == info)
              { 
                 cout<<"The value entered found at position     : "<<counter<<endl; 
                 return main();             
              }
              else
              {
              temp1= temp1->next;       // points to the next node
              }
        }

You neglected to specify what the problem you're having is, but I do have some notes on the code as it stands:

temp1 = (node*)malloc(sizeof(node)); // allocate space for node
temp1 = head;

You allocate space for a node, then immediately throw away your only reference to it. Not a good idea. The search algorithm for a linked list shouldn't require any space beyond a pointer.

bool find = false;

find is already used in C++ as the name of a standard library function. You should avoid reusing such names.

cout<<"The value entered found at position : "<<counter<<endl;

counter is never updated within the loop.

return main();

Never call main() recursively. Technically it's not even legal in C++, but even for compilers that allow such nonsense, it's a terrible idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.