Question: Hello, I am working on this project for class. this is the .h and imp for my orderedLinkedList. The problem I am having is that
Hello, I am working on this project for class. this is the .h and imp for my "orderedLinkedList". The problem I am having is that I keep getting the error--use of undeclared identifier first, use of undeclared identifier last, and Reference ot overlaoded function could not be resolved; did you mean to call it. I've went through my code many times and cannot figure this one out. I am using xcode 7.3 (7D175). If I could get any help with this, it would be much appreciated.
#ifndef H_orderedListType
#define H_orderedListType
#include "linkedList.h"
/*Refereceing page 1106 from our text*/
using namespace std;
template
class orderedLinkedList: public linkedListType
{
public:
bool search(const Type& searchItem) const;
//Function to determine whether searchItem is in the list.
//Postcondition: Returns true if searchItem is in the list,
// otherwise the value false is returned.
void insert(const Type& newItem);
//Function to insert newItem in the list.
//Postcondition: first points to the new list, newItem
// is inserted at the proper place in the list, and
// count is incremented by 1.
void insertFirst(const Type& newItem);
//Function to insert newItem at the beginning of the list.
//Postcondition: first points to the new list, newItem is
// inserted at the beginning of the list, last points to the
// last node in the list, and count is incremented by 1.
void insertLast(const Type& newItem);
//Function to insert newItem at the end of the list.
//Postcondition: first points to the new list, newItem is
// inserted at the end of the list, last points to the
// last node in the list, and count is incremented by 1.
void deleteNode(const Type& deleteItem);
//Function to delete deleteItem from the list.
//Postcondition: If found, the node containing deleteItem is
// deleted from the list; first points to the first node
// of the new list, and count is decremented by 1. If
// deleteItem is not in the list, an appropriate message
// is printed.
};
template
bool orderedLinkedList
{
bool found = false;
nodeType
current = first; //start the search at the first node //ERROR HERE--use of undeclared identifier
while (current != nullptr && !found)
if (current->info >= searchItem)
found = true;
else
current = current->link;
if (found)
found = (current->info == searchItem); //test for equality
return found;
}//end search
template
void orderedLinkedList
{
nodeType
nodeType
nodeType
bool found;
newNode = new nodeType
newNode->info = newItem; //store newItem in the node
newNode->link = nullptr; //set the link field of the node
//to nullptr
if (first == nullptr) //Case 1 ERROR HERE--use of undeclared identifier 'first'
{
first = newNode; ERROR HERE--use of undeclared identifier 'first'
last = newNode; ERROR HERE--use of undeclared identifier 'last'
count++; ERROR HERE--Reference to overloaded function could not be resolved; did you mean to call it?
}
else
{
current = first;
found = false;
while (current != nullptr && !found) //search the list
if (current->info >= newItem)
found = true;
else
{
trailCurrent = current;
current = current->link;
}
if (current == first) //Case 2
{
newNode->link = first;
first = newNode;
count++;
}
else //Case 3
{
trailCurrent->link = newNode;
newNode->link = current;
if (current == nullptr)
last = newNode;
count++;
}
}//end else
}//end insert
template
void orderedLinkedList
{
insert(newItem);
}//end insertFirst
template
void orderedLinkedList
{
insert(newItem);
}//end insertLast
template
void orderedLinkedList
{
nodeType
nodeType
bool found;
if (first == nullptr) //Case 1
cout << "Cannot delete from an empty list." << endl;
else
{
current = first;
found = false;
while (current != nullptr && !found) //search the list
if (current->info >= deleteItem)
found = true;
else
{
trailCurrent = current;
current = current->link;
}
if (current == nullptr) //Case 4
cout << "The item to be deleted is not in the "
<< "list." << endl;
else
if (current->info == deleteItem) //the item to be
//deleted is in the list
{
if (first == current) //Case 2
{
first = first->link;
if (first == nullptr)
last = nullptr;
delete current;
}
else //Case 3
{
trailCurrent->link = current->link;
if (current == last)
last = trailCurrent;
delete current;
}
count--;
}
else //Case 4
cout << "The item to be deleted is not in the "
<< "list." << endl;
}
}//end deleteNode
#endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
