Okay I fixed my code and this is what i got but i cant reprint the list and take out the desired number.
its at the bottom
#include<iostream.h>
struct ListNode
{
int number;
ListNode *link;
};
typedef ListNode* ListNodePtr;
void insertNodeAtFront(ListNodePtr&, int);
void printList(ListNodePtr);
void printReversed(ListNodePtr);
ListNodePtr search(ListNodePtr, int);
void insertAfter(ListNodePtr, int);
void insertAtRear(ListNodePtr, int);
void removeNode(ListNodePtr, ListNodePtr);
void main()
{
ListNodePtr head = new ListNode;
head -> number = 5;
head -> link = NULL;
for(int i = 0; i < 20; i++)
insertNodeAtFront(head, 10*i);
//printList(head);
//printReversed(head);
cout << "What number would you like to find?" << endl;
int target;
cin >> target;
ListNodePtr result = search(head, target);
if(result != NULL)
insertAfter(result, 18);
cout << "What item would you like to remove?" << endl;
cin >> target;
result = search(head, target);
if(result != NULL)
removeNode(head, result);
insertAtRear(head, 99);
printList(head);
int a;
cin >> a;
}
void insertNodeAtFront(ListNodePtr& home, int num)
{
ListNodePtr tempPtr = new ListNode;
tempPtr -> number = num;
tempPtr -> link = home;
home = tempPtr;
}
void printList(ListNodePtr home)
{
for(ListNodePtr here = home; here != NULL; here = here ->link)
{
cout << here -> number << endl;
}
cout << "done" << endl;
}
void printReversed(ListNodePtr here)
{
if(here != NULL)
{
printReversed(here -> link);
cout << here ->number << endl;
}
}
ListNodePtr search(ListNodePtr here, int target)
{
ListNodePtr tempPtr = here;
while((tempPtr -> number != target)&&(tempPtr -> link != NULL))
tempPtr = tempPtr -> link;
if(tempPtr -> number == target)
return tempPtr;
else
return NULL;
}
void insertAfter(ListNodePtr here, int num)
{
ListNodePtr tempPtr = new ListNode;
tempPtr -> number = num;
tempPtr -> link = here -> link;
here -> link = tempPtr;
}
void insertAtRear(ListNodePtr head, int num)
{
ListNodePtr tempPtr = new ListNode;
tempPtr -> number = num;
tempPtr -> link = NULL;
ListNodePtr finder = head;
while(finder -> link != NULL)
finder = finder -> link;
finder -> link = tempPtr;
}
//right here
void removeNode(ListNodePtr head, ListNodePtr here)
{
ListNode *cursor;
for(cursor = head; cursor->link != here; cursor = cursor -> link)
{
cursor->link = head -> link;
}
}
cant get the list to reprint out and take out the desired number.