I am having trouble writing these recursive functions. I know I am on the right track, but also know that these functions are not right. Any help would be appreciated.
Given the following declarations for a linked list:
struct NodeType;
struct NodeType {
int info;
NodeType* link;
};
typedef NodeType* NodePtr;
2.1. Write a recursive value-returning function Search that searches a dynamic linked list for the integer value key. If the value is in the list, the function should return a pointer to the node where it was found. If the value is not in the list, the function should return NULL.
NodePtr Search(NodePtr head, int key) {
...
}
2.2. Write a recursive value-returning function FindMax that returns the maximum value in a dynamic linked list of integers.
int FindMax(NodePtr head) {
...
}
this is what I have so far
for 2.1
NodePtr Search( NodePtr head, key)
{
NodePtr current;
current=head;
if(current==NULL)
{
return NULL;
}
while(current!=NULL)
{
if(current->info==key)
{
return current->info;
}
while(current->info!=key)
{
Search (head->link);
}
}
for 2.2
int FindMax (NodePtr head)
{
NodePtr current;
current=head;
int value;
if(current==NULL)
{
return NULL;
}
while(current!=NULL)
{
if(current->info > current->link->info)
value=current->info;
else
value=current->link->info;
FindMax(head->info);
}
}