Question
my linkedListType.h: #ifndef LINKEDLISTTYPE_H_ #define LINKEDLISTTYPE_H_ #include #include linkedListIterator.h template class linkedListType{ public: const linkedListType &operator= (const linkedListType &); //overload = operator void initializeList(); //initialize
my linkedListType.h:
#ifndef LINKEDLISTTYPE_H_
#define LINKEDLISTTYPE_H_
#include
#include "linkedListIterator.h"
template
class linkedListType{
public:
const linkedListType
(const linkedListType
//overload = operator
void initializeList();
//initialize list to empty
bool isEmptyList();
//function to see if list is empty
void print() const;
//function to print data from each node
int length() const;
//function to return # of nodes in list
void destroyList();
//function to delete all nodes
Type front() const;
//function to return first element of list
Type back() const;
//function to return last element of list
virtual bool search(const Type& searchItem) const = 0;
//function to see if seatchItem is in the list
virtual void insertFirst(const Type& newItem) = 0;
//function to insert newItem at beginning of list
virtual void insertLast(const Type& newItem) = 0;
//function to insert newItem at end of list
virtual void deleteNode(const Type& deleteItem) = 0;
//function to delete a node from list
linkedListIterator
//function to return an iterator at the beginning of list
linkedListIterator
//function to return an iterator one element past the last element
linkedListType();
//default constructor
linkedListType(const linkedListType
//copy constructor
~linkedListType();
//destructor
protected:
int count;
//variable to store number of elements in list
nodeType
nodeType
private:
void copyList(const linkedListType
//function to make a copy of otherList
};
template
bool linkedListType
return (first == nullptr);
}
template
linkedListType
first = nullptr;
last = nullptr;
count = 0;
}
template
void linkedListType
nodeType
while(first != nullptr){
temp = first; //assign temp to first
first = first->next; //move first to next node
delete temp; //delete temp from memory
}
last = nullptr;
count = 0;
}
template
void linkedListType
destroyList(); //if list has nodes, delete them
}
template
void linkedListType
nodeType
current = first;
while(current != nullptr){
cout info
current = current->next;
}
}
template
int linkedListType
return count;
//end of length
}
template
Type linkedListType
assert(first != nullptr);
return first->info; //retrrn info of first node
}
template
Type linkedListType
assert(last != nullptr);
return last->info; //return info of last
}
template
linkedListIterator
linkedListIterator
return temp;
}
template
linkedListIterator
linkedListIterator
return last;
}
template
void linkedListType
nodeType
nodeType
if(first != nullptr){//if list is not empty
destroyList();
}
if(otherList->first == nullptr){//otherList is empty
first = nullptr;
last = nullptr;
count = 0;
}
else{
current = otherList->first; // current points tp list to be copied
count = otherList->count;
//copy first node
first = new nodeType
first->info = current->info; // copy info
first->next = nullptr;
last = first; //make last equal to first if one node available
current = current->next; //make current point to next node
//copy remaining list
while(current != nullptr){
newNode = new nodeType
newNode->info = current->info; //copy the info
newNode->next = nullptr; //set next pointer to null
last->next = newNode; //point last to newNode
last = newNode; //move last to newNode and newNode will be last
/ode in list
current = current->next; //move current to next node
}//end of while
}//end of else
}//end of copyList
template
linkedListType
destroyList();
}//end destructor
template
linkedListType
(const linkedListType
first = nullptr;
copyList(otherList);
}//end of copy constructor
//overload assignment operator
template
const linkedListType
(const linkedListType
if(this != &otherList){ //to avoid self-copy
copyList(&otherList);
}
return *this;
}
#endif /* LINKEDLISTTYPE_H_ */
--------------------------------------------------------------------
linkedListIterator.h:
#ifndef LINKEDLISTITERATOR_H_
#define LINKEDLISTITERATOR_H_
#include
#include
using namespace std;
template
class nodeType{
public:
Type info;
nodeType
//to not confuse myself
};
template
class linkedListIterator{
public:
linkedListIterator();
//default constructor
linkedListIterator(nodeType
//constructor w/ parameters
Type operator*();
//function to overload dereferencing operator *
linkedListIterator
//function to overload pre-increment operator ++
bool operator==(const linkedListIterator
//overload the equality operator
bool operator!=(const linkedListIterator
//overload the not equal operator
private:
nodeType
//pointer to point to current node in list
};
template
linkedListIterator
current = nullptr;
}
template
linkedListIterator
current = ptr;
}
template
Type linkedListIterator
return current->info;
}
template
linkedListIterator
current = current->next;
return *this;
}
template
bool linkedListIterator
(const linkedListIterator
return (current == right.current);
}
template
bool linkedListIterator
(const linkedListIterator
return (current != right.current);
}
#endif /* LINKEDLISTITERATOR_H_ */
HOMEWORK #23-Extending the linkedListType Class. Extend the class linkedListType by adding the following operations: 1. Find and delete the node with the smallest info in the list. Delete only the first occurrence and traverse the list only once. Use a purely virtual function: virtual void deleteSmallest()0 // Function to delete smallest element in the list // Postcondition: first points to beginning of list, last points to end of list, count decremented by 1 2. Find and delete the node with the largest info in the list. Delete only the first occurrence and traverse the list only once. Use a pure virtual function: virtual void deleteLargest () 0; // Function to delete largest element in the list // Postcondition: first points to beginning of list, last points to end of list, count decremented by 1 HOMEWORK #23-Extending the linkedListType Class. Extend the class linkedListType by adding the following operations: 1. Find and delete the node with the smallest info in the list. Delete only the first occurrence and traverse the list only once. Use a purely virtual function: virtual void deleteSmallest()0 // Function to delete smallest element in the list // Postcondition: first points to beginning of list, last points to end of list, count decremented by 1 2. Find and delete the node with the largest info in the list. Delete only the first occurrence and traverse the list only once. Use a pure virtual function: virtual void deleteLargest () 0; // Function to delete largest element in the list // Postcondition: first points to beginning of list, last points to end of list, count decremented by 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started