Hey all the Gurus out there...need a little assistance with adding a node and deleting a node...I have the code below...hopefully somebody can make something out of the mess!!!
THIS TESTS THE ADDING:
void TestAddNode (NodePtr List)
{
char NewChar;
cout << "\n\n---------------- Testing AddNode -------------------\n\n";
cout << "Character to be added? ";
NewChar = getch();
if (NewChar == '\r') // User pressed just enter key.
{
cout << "Aborting AddNode...";
return;
}
cout << NewChar;
cout << " -- Adding \'" << NewChar << "\'";
AddNode (NewChar, List);
cout << "\n\nThe new list: ";
ShowList(List);
}
THIS IS TRYING TO ADD THE NODE:
void AddNode (char NewChar,
NodePtr List)
{
NodePtr NewNode;
NewNode = List;
if (NewChar != '\n')
{
NewNode->Link = new Node;
if (NewNode->Link == NULL)
AbortProgram();
else
{
NewNode = NewNode->Link;
NewNode->Ch = NewChar;
NewNode->Link = NULL;
}
}
}
THIS IS TO TEST DELETE NODE:
void TestDeleteNode (NodePtr List)
{
int CharFound;
char CharToBeDeleted;
cout << "\n\n***************** Testing DeleteNode *******************";
cout << "\n\nCharacter to be deleted? ";
CharToBeDeleted = getch();
cout << CharToBeDeleted;
DeleteNode (CharToBeDeleted, List, CharFound);
if ( CharFound )
cout << "\n\n'" << CharToBeDeleted << "' has been deleted,";
else
cout << "\n\n'" << CharToBeDeleted << "' was not in the list,";
cout << "\n\nList = ";
ShowList(List);
}
THIS IS FOR DELETING NODE:
void DeleteNode (char CharToDelete,
NodePtr List,
int &CharFound)
{
NodePtr NodeToBeDeleted;
if (List->Ch == CharToDelete)
{
NodeToBeDeleted = List;
List = List->Link;
delete NodeToBeDeleted;
List->Link = NULL;
CharFound = 1;
}
else
CharFound = 0;
}
ANY HELP WOULD BE MUCH APPRECIATED!!!
Thanks!