I am new to link list and I have this problem where you have two lists. One list pointed by HEAD has a list of numbers in it, and the second list pointed by LARGE that contains the highest element(s) in the list pointed by HEAD. Each element has three fields: name, value, and link (I think the problem assumes the link is the pointer to the next node). Say for example you have a list 31 28 25 31 29 29 30 31 so the program will copy the highest value(s), here been 31(and its associated variables: name and link) into the list pointed by LARGE. On top of that, you delete those highest value(s) (including the name and link) in the list pointed by HEAD. So list pointed by HEAD will now have: 28 25 29 29 30 and list pointed by LARGE will have: 31 31 31. This is what I have so far (pseudo-code):
I am having trouble as to how to send the other values to the new list (name and link), and how to delete the old nodes from the original list (do not know how I can tell the program that this value came from the first node of orginial use delete using this method, or this value was found some where in between so you this method, since deleting the first node, last node, anything in between are three different algorithms to do it).
Algorithm node (struct node *HEAD)
Input: List with name, value, and link
Output: The orginial list without the highest value(s), and a list pointed by LARGE that contains the highest value(s) found in the list pointed by HEAD
struct node *LARGE;
node *currentVal = HEAD;
node *currentLargeVal = LARGE;
node *temp1;
node * temp2;
node *next = [U][B]link[/B][/U];
int p, q, Max;
if(currentVal == NULL)
{
cout<<"Empty list"<<endl;
}
else
{
temp1 = currentVal;
for(currentVal = HEAD; currentVal != NULL; currentVal->next)
{
p = temp1->value;
q = temp1->next->value;
if( p >= q)
{
Max = p;
}
else
{
Max = q;
}
}
}// End of traversing the list to find the Max value in list pointed by HEAD
temp1 = currentVal;
temp2 = currentLargeVal;
for(currentVal = HEAD; currentVal != NULL; currentVal->next)
{
if(temp1->value == Max)
{
if(currentLargeVal != NULL)
{ while (temp2 -> next != NULL)
{
temp2= temp2->next;
}
temp2->next = Max;
}
}
}