tags:

views:

185

answers:

4

Hello to every body

I hope every one keep in best state.

I want to help me in solve this problem in my Sheet .

I use recurrence functions in like list.( with ADT file ) by modify the search function and adding Printing function in a Reverse Manner.

template <class TYPE, class KTYPE> 
bool List<TYPE, KTYPE> :: _search (NODE<TYPE> **pPre,
              NODE<TYPE> **pLoc, 
              KTYPE        key)
{
   if ((*pLoc) == NULL)
        return false;
   else
     if (key == (*pLoc)->data.key)
            return true;

         _search ((*pPre)->link ,(*pLoc)->link, key);

      return false;
}

template bool List :: _search (NODE **pPre, NODE *pLoc, KTYPE key) { if ((pLoc) == NULL) return false; else if (key == (*pLoc)->data.key) return true; search ((pPre)->link ,(*pLoc)->link, key); return false; }

put taken error in

_search ((*pPre)->link ,(*pLoc)->link, key);

I don't Know why? I tru to put or delete * put not any answer

the error:

error C2664: 'List<TYPE,KTYPE>::_search' : cannot convert parameter 1 from 'NODE<TYPE> *' to 'NODE<TYPE> **'

and I initialize it : Help with Code Tags (Toggle Plain Text)

NODE * pPre; pPre = NULL; NODE * pLoc ; pLoc = NULL;

NODE * pPre; pPre = NULL; NODE * pLoc ; pLoc = NULL; befor the function calling

this function return the location of pPre and pLoc in memory , so must the function signature keep of **. So , must to change the way you are calling it. but how ?

Help with Code Tags (Toggle Plain Text)

template <class  TYPE> 
    struct NODE 
      {
       TYPE    data;
       NODE   *link;
      }; 

    struct Student 
      {
       string name ;   
       int level;
       int key;
      }; 

template <class  TYPE, class KTYPE> 
    class List  
       {
         private:
           NODE<TYPE> *head;
           NODE<TYPE> *pos;
           NODE<TYPE> *rear;
           int         count;
                     ....
                     .... 
                    ....
                     ....
                     ....

};

template struct NODE { TYPE data; NODE *link; }; struct Student { string name ; int level; int key; }; template class List { private: NODE *head; NODE *pos; NODE *rear; int count; .... .... .... .... .... };

and the print Function

 ostream & operator << (ostream  & out , Student & Data)
{
    out << "The name is : " << Data.name << "\nThe Level is : " << Data.level<< "\nThe ID is :"<<Data.key;
    return out;
}

template<class TYPE, class KTYPE> 
void List <TYPE, KTYPE > :: ReversePrint ( NODE <TYPE> * node )
{
if ( node== NULL)  
        return ;

ReversePrint (node->link);

cout << node-> data;

   return ;
}

thank you to help me

+2  A: 
_search ((*pPre)->link ,(*pLoc)->link, key);

The first parameter is of type pointer to NODE whereas it should be a pointer to a pointer to NODE.

dirkgently
A: 
_search ((*pPre)->link ,(*pLoc)->link, key);

change the above to :

_search (&(*pPre)->link ,(*pLoc)->link, key); <== see & in first parameter

It first parameter requires pointer to NODE*

EDIT: After checking your code after EDIT it looks like both 1st and 2nd the parameters passing to _search is not correct. The method requires pointer to pointer to NODE. Hence, the correct way of passing parameter is:

_search (&(*pPre)->link , &(*pLoc)->link, key);
aJ
A: 

when i change it i have these error:

error C2664: 'List::_search' : cannot convert parameter 2 from 'NODE *' to 'NODE **'

then, i change it to: search (&(pPre)->link ,&(*pLoc)->link, key); but i get another error:

error LNK2005: "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,struct Student &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAUStudent@@@Z) already defined in ADT6.obj main.obj

and fatal error LNK1169: one or more multiply defined symbols found

please my god help me :(

@Abeer, The _search appears twice in your posted code. Please check if the original code also has the same ? Also, the student definition appears twice.
aJ
Also, you should EDIT your post or add comments to your question instead of posting your query in Answer section.
aJ
A: 

look..iam sory to write here but i can't add comment because commenting requires 50 reputation

so, i was write here:

template bool List :: _search (NODE **pPre, NODE *pLoc, KTYPE key){ if ((pLoc) == NULL) return false; else if (key == (*pLoc)->data.key) return true; search ((pPre)->link ,(*pLoc)->link, key); return false;}

put taken error in

search ((pPre)->link ,(*pLoc)->link, key);

the error:

error C2664: 'List::_search' : cannot convert parameter 1 from 'NODE *' to 'NODE **

I change to

search (&(pPre)->link , &(*pLoc)->link, key);

but the erorre is the rest.

please help me. rest only 2 hour at must to send the program

=========== and the print Function

ostream & operator << (ostream & out , Student & Data){ out << "The name is : " << Data.name << "\nThe Level is : " << Data.level<< "\nThe ID is :"< void List :: ReversePrint ( NODE * node ){if ( node== NULL) return ;ReversePrint (node->link);cout << node-> data; return ;}

=============

but the erorre is the rest.

please help me. rest only 2 hour at must to send the program