Question: 1 ////////////////////////////////////////////////////////////// #pragma once #include #include #include LinkedListType.h using namespace std; template struct nodeType { Type info; nodeType *link; }; template class linkedListIterator { public:

1 //////////////////////////////////////////////////////////////
#pragma once
#include
#include
#include "LinkedListType.h"
using namespace std;
template
struct nodeType
{
Type info;
nodeType
};
template
class linkedListIterator
{
public:
linkedListIterator();
linkedListIterator(nodeType
Type operator*();
linkedListIterator
bool operator==(const linkedListIterator
bool operator!=(const linkedListIterator
private:
nodeType
};
//***************** class linkedListType ****************
template
class linkedListType
{
public:
const linkedListType
void initializeList();
bool isEmptyList() const;
void print() const;
int length() const;
void destroyList();
Type front() const;
Type back() const;
virtual bool search(const Type& searchItem) const = 0;
virtual void insertFirst(const Type& newItem) = 0;
virtual void insertLast(const Type& newItem) = 0;
virtual void deleteNode(const Type& deleteItem) = 0;
virtual void deleteAll(const Type& deleteItem) = 0;
virtual void deleteSmallest() = 0;
linkedListIterator
linkedListIterator
linkedListType();
linkedListType(const linkedListType
~linkedListType();
protected:
int count;
nodeType
nodeType
private:
void copyList(const linkedListType
};
//////////////////////////////////////////////////////////////////////////////////////////////////
//***************** class linkedListIterator ****************
template
linkedListIterator
{
current = nullptr;
}
template
linkedListIterator
{
current = ptr;
}
template
Type linkedListIterator
{
return current->info;
}
template
linkedListIterator
operator++()
{
current = current->link;
return *this;
}
template
bool linkedListIterator
{
return (current == right.current);
}
template
bool linkedListIterator
{
return (current != right.current);
}
//***************** class linkedListType ****************
template
bool linkedListType
{
return (first == nullptr);
}
template
linkedListType
{
first = nullptr;
last = nullptr;
count = 0;
}
template
void linkedListType
{
nodeType
while (first != nullptr)
{
temp = first;
first = first->link;
delete temp;
}
last = nullptr;
count = 0;
}
template
void linkedListType
{
destroyList();
}
template
void linkedListType
{
nodeType
current = first;
while (current != nullptr)
{
cout info
current = current->link;
}
}
template
int linkedListType
{
return count;
}
template
Type linkedListType
{
assert(first != nullptr);
return first->info;
}
template
Type linkedListType
{
assert(last != nullptr);
return last->info;
}
template
linkedListIterator
{
linkedListIterator
return temp;
}
template
linkedListIterator
{
linkedListIterator
return temp;
}
template
void linkedListType
{
nodeType
nodeType
if (first != nullptr)
destroyList();
if (otherList.first == nullptr)
{
first = nullptr;
last = nullptr;
count = 0;
}
else
{
current = otherList.first;
count = otherList.count;
first = new nodeType
first->info = current->info;
first->link = nullptr;
last = first;
current = current->link;
while (current != nullptr)
{
newNode = new nodeType
newNode->info = current->info;
newNode->link = nullptr;
last->link = newNode;
last = newNode;
current = current->link;
}
}
}
template
linkedListType
{
destroyList();
}
template
linkedListType
{
first = nullptr;
copyList(otherList);
}
template
const linkedListType
{
if (this != &otherList)
{
copyList(otherList);
}
return *this;
}
2 /////////////////////////////////////
#pragma once #include "LinkedListType.h" templateclass orderedLinkedList : public linkedListType { public: bool search(const Type& searchItem) const; void insert(const Type& newItem); void insertFirst(const Type& newItem); void insertLast(const Type& newItem); void deleteNode(const Type& deleteItem); void deleteAll(const Type& deleteItem); void deleteSmallest(); }; template bool orderedLinkedList ::search(const Type& searchItem) const { bool found = false; nodeType *current; current = first; while (current != nullptr && !found) if (current->info >= searchItem) current->info == searchItem? found = true: found = false; else current = current->link; if (found) found = (current->info == searchItem); return found; } template void orderedLinkedList ::insert(const Type& newItem) { nodeType *current; nodeType *trailCurrent = nullptr; nodeType *newNode; bool found; newNode = new nodeType ; newNode->info = newItem; newNode->link = nullptr; if (first == nullptr) { first = newNode; last = newNode; count++; } else { current = first; found = false; while (current != nullptr && !found) if (current->info >= newItem) found = true; else { trailCurrent = current; current = current->link; } if (current == first) { newNode->link = first; first = newNode; count++; } else { trailCurrent->link = newNode; newNode->link = current; if (current == nullptr) last = newNode; count++; } } } template void orderedLinkedList ::insertFirst(const Type& newItem) { insert(newItem); } template void orderedLinkedList ::insertLast(const Type& newItem) { insert(newItem); } template void orderedLinkedList ::deleteNode(const Type& deleteItem) { nodeType *current; nodeType *trailCurrent = nullptr; bool found; if (first == nullptr) cout info >= deleteItem) found = true; else { trailCurrent = current; current = current->link; } if (current == nullptr) cout info == deleteItem) { if (first == current) { first = first->link; if (first == nullptr) last = nullptr; delete current; } else { trailCurrent->link = current->link; if (current == last) last = trailCurrent; delete current; } count--; } else cout void orderedLinkedList ::deleteAll(const Type& deleteItem) { // Not implemented } template void orderedLinkedList ::deleteSmallest() { // Not implemented }
3 //////////////
//Programming Exercise 2: Test Program //38 70 20 6 51 82 70 1 66 44 70 70 99 120 63 6 -999 #include "stdafx.h" #include#include "orderedLinkedListType.h" using namespace std; int main() { orderedLinkedList list1; int num; cout > num; while (num != -999) { list1.insert(num); cin >> num; } cout The function insert of the class orderedLinkedList does not check if the item to be inserted is already in the list; that is, it does not check for duplicates. Rewrite the definition of the function insert so that before inserting the item, it checks whether the item to boe inserted is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message. Note: Use the attached code as a start point. The test code is given to you LinkedListType(2)h orderedLinkedListType 1).h test 3) cop Attach File The function insert of the class orderedLinkedList does not check if the item to be inserted is already in the list; that is, it does not check for duplicates. Rewrite the definition of the function insert so that before inserting the item, it checks whether the item to boe inserted is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message. Note: Use the attached code as a start point. The test code is given to you LinkedListType(2)h orderedLinkedListType 1).h test 3) cop Attach File
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
