temp = new(nothrow)Node; // allocate space for a new
// node and store its address in temp
temp->data = dataIn; // copy the data over into
// the new node
temp->link = NULL; // and this new node is
// not pointing at any other node
// is the linked list empty?
if(top == NULL) {
// if so this new node is the first node into the linked list
top = temp;
rear = temp;
}else { // else already
// have some nodes in the linked list
rear->link = temp; // the last node; link
// it to the new node
rear = temp; // now make this new
// node the last node
}
count++; // shows that we have added one more node
}
// function to display the items on the list
bool LList::displayLList();
{
Node *temp = top; // gets the address of the first item on
// the list
if (temp == NULL)
cout << "\nThe Linked List is empty...\n";
else {
while(temp!= NULL) {
cout << "Key: " << temp->key << " Name: " << temp->name
<< "\n";
temp = temp->link;
}
cout << endl;
}
}
bool LList::removeItem(int keyIn)
{
Node *nodeOut; // will contain address of the node to remove
bool retFlag;
char resp;
retFlag = searchLList(nodeOut,keyIn);
if(retFlag == true) { // we were able to find the node
cout << "Key: " << nodeOut->key << " Name: " << nodeOut->name
<< "\n";
cout << "\n\nDo you really want to remove this node? (Y/N): ";
cin >> resp;
//--- delete node -----
}
// free the memory held up by the linked list
void LList::freeLLMemory()
{
Node *temp = top; // gets the address of the first item on
// the list