void append(struct node **head, int data)
{
struct node *temp;
temp = *head;
if (temp == NULL)
{
temp = new (struct node);
temp -> info = data;
temp -> next = NULL;
*head = temp;
}
else
if (head != NULL)
{
append(&(*head)->next,data);
}
}
void show(struct node *first)
{
if (first != NULL)
{
cout<<first->info<<endl;
show(first->next);
}
}
void findgreatest(struct node *first)
{
if (first != NULL)
{
int temp = first->info;
if (temp > max)
max = temp;
findgreatest(first->next);
}
}
int main()
{
static int max = 0;
struct node *p;
append(&p,43);
append(&p,33);
append(&p,63);
show(p);
findgreatest(p);
return 0;
}
------i get the following error when i try to compile------------------
test1.cpp: In function ‘void findgreatest(node*)’:
test1.cpp:43: error: invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator>’
test1.cpp:44: error: overloaded function with no contextual type information
----------------------------------------------------------------
please help...
findgreatest() has no knowledge of "max" defined in main(). I think you're getting these errors because the compiler thinks that you're referring to std::max(). This is a good example of when it would be better not to use namespace std.
You could make max a global declared before findgreatest() or you could make findgreatest() non recursive and have max as a local.