For Linked Lists, I know the code for insertBack and deleteFront....but How do I change insertBack into insertFront and deleteFront into deleteBack with the code I currently have? Please help!
deleteFront code:
void deleteFront(nodeType*& first)
{
nodeType *last,*current,*trailcurrent;
bool found;
int num;
cout<<endl;
cout<<"Inside deleteFront...removing item from front of list..."<<endl;
cout<<endl;
if (first->info == 1)
{
current = first;
first = first->link;
}
if (first == NULL)
{
last = NULL;
delete current;
}
else
{
found = false;
trailcurrent = first;
current = first->link;
}
}
Insert Back code:
void insertBack(nodeType*& last)
{
int num;
nodeType *first,*newNode;
cout<<endl;
cout<<"Enter a number to add to the END of the list: "<<endl;
cin>>num;
newNode = new nodeType;
newNode->info = num;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
}