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;

1 //////////////////////////////////////////////////////////////

#pragma once

#include

#include

#include "LinkedListType.h"

using namespace std;

template

struct nodeType

{

Type info;

nodeType *link;

};

template

class linkedListIterator

{

public:

linkedListIterator();

linkedListIterator(nodeType *ptr);

Type operator*();

linkedListIterator operator++();

bool operator==(const linkedListIterator& right) const;

bool operator!=(const linkedListIterator& right) const;

private:

nodeType *current;

};

//***************** class linkedListType ****************

template

class linkedListType

{

public:

const linkedListType& operator=(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 begin();

linkedListIterator end();

linkedListType();

linkedListType(const linkedListType& otherList);

~linkedListType();

protected:

int count;

nodeType *first;

nodeType *last;

private:

void copyList(const linkedListType& otherList);

};

//////////////////////////////////////////////////////////////////////////////////////////////////

//***************** class linkedListIterator ****************

template

linkedListIterator::linkedListIterator()

{

current = nullptr;

}

template

linkedListIterator::linkedListIterator(nodeType *ptr)

{

current = ptr;

}

template

Type linkedListIterator::operator*()

{

return current->info;

}

template

linkedListIterator linkedListIterator::

operator++()

{

current = current->link;

return *this;

}

template

bool linkedListIterator::operator==(const linkedListIterator& right) const

{

return (current == right.current);

}

template

bool linkedListIterator::operator!=(const linkedListIterator& right) const

{

return (current != right.current);

}

//***************** class linkedListType ****************

template

bool linkedListType::isEmptyList() const

{

return (first == nullptr);

}

template

linkedListType::linkedListType()

{

first = nullptr;

last = nullptr;

count = 0;

}

template

void linkedListType::destroyList()

{

nodeType *temp;

while (first != nullptr)

{

temp = first;

first = first->link;

delete temp;

}

last = nullptr;

count = 0;

}

template

void linkedListType::initializeList()

{

destroyList();

}

template

void linkedListType::print() const

{

nodeType *current;

current = first;

while (current != nullptr)

{

cout info

current = current->link;

}

}

template

int linkedListType::length() const

{

return count;

}

template

Type linkedListType::front() const

{

assert(first != nullptr);

return first->info;

}

template

Type linkedListType::back() const

{

assert(last != nullptr);

return last->info;

}

template

linkedListIterator linkedListType::begin()

{

linkedListIterator temp(first);

return temp;

}

template

linkedListIterator linkedListType::end()

{

linkedListIterator temp(nullptr);

return temp;

}

template

void linkedListType::copyList(const linkedListType& otherList)

{

nodeType *newNode;

nodeType *current;

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::~linkedListType()

{

destroyList();

}

template

linkedListType::linkedListType(const linkedListType& otherList)

{

first = nullptr;

copyList(otherList);

}

template

const linkedListType& linkedListType::operator=(const linkedListType& otherList)

{

if (this != &otherList)

{

copyList(otherList);

}

return *this;

}

2 /////////////////////////////////////

#pragma once #include "LinkedListType.h" template  class 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!