Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am working on this project for class. this is the .h and imp for my \"o

ID: 3692746 • Letter: H

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 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 Type>

class orderedLinkedList: public linkedListType<Type>

{

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 <class Type>

bool orderedLinkedList<Type>::search(const Type& searchItem) const

{

bool found = false;

nodeType<Type> *current; //pointer to traverse the list

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 <class Type>

void orderedLinkedList<Type>::insert(const Type& newItem)

{

nodeType<Type> *current; //pointer to traverse the list

nodeType<Type> *trailCurrent; //pointer just before current

nodeType<Type> *newNode; //pointer to create a node

bool found;

newNode = new nodeType<Type>; //create the node

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<class Type>

void orderedLinkedList<Type>::insertFirst(const Type& newItem)

{

insert(newItem);

}//end insertFirst

template<class Type>

void orderedLinkedList<Type>::insertLast(const Type& newItem)

{

insert(newItem);

}//end insertLast

template<class Type>

void orderedLinkedList<Type>::deleteNode(const Type& deleteItem)

{

nodeType<Type> *current; //pointer to traverse the list

nodeType<Type> *trailCurrent; //pointer just before current

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

Explanation / Answer

The problem with your code is:

You didn't declared the private variables in your orderedLinkedList class. Initially, the orderedLInkedList is supposed to have both the first, and last pointers, and count. And both the pointers should be pointing to NULL, and count should be initialized to 0, when you are creating an object of type orderedLinkedList. Here is the updated code for you, with no compilation errors. Hope this will solve your problem.

#ifndef H_orderedListType

#define H_orderedListType

#include "linkedList.h"

/*Refereceing page 1106 from our text*/
using namespace std;

template <class Type>
class orderedLinkedList: public linkedListType<Type>
{
nodeType<Type> *first;
nodeType<Type> *last;
int count;
public:
orderedLinkedList()
{
first = NULL;
last = NULL;
count = 0;
}
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 <class Type>
bool orderedLinkedList<Type>::search(const Type& searchItem) const
{
bool found = false;
nodeType<Type> *current; //pointer to traverse the list

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 <class Type>
void orderedLinkedList<Type>::insert(const Type& newItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
nodeType<Type> *newNode; //pointer to create a node

bool found;

newNode = new nodeType<Type>; //create the node
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<class Type>
void orderedLinkedList<Type>::insertFirst(const Type& newItem)
{
insert(newItem);
}//end insertFirst

template<class Type>
void orderedLinkedList<Type>::insertLast(const Type& newItem)
{
insert(newItem);
}//end insertLast

template<class Type>
void orderedLinkedList<Type>::deleteNode(const Type& deleteItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote