Question: Linked List type 1 include using namespace std; #ifndef LINKEDLISTTYPE_H_INCLUDED #define LINKEDLISTTYPE_H_INCLUDED //Definition of the node template struct nodeType { Type info; nodeType *link; };

"Linked List type 1"
include
using namespace std;
#ifndef LINKEDLISTTYPE_H_INCLUDED
#define LINKEDLISTTYPE_H_INCLUDED
//Definition of the node
template
struct nodeType
{
Type info;
nodeType *link;
};
template
class linkedListType
{
public:
void initializeList();
bool isEmptyList() const;
void print() const;
int length() const;
void destroyList();
Type front() const;
Type back() const;
bool search(const Type& searchItem) const;
void insertFirst(const Type& newItem);
void insertLast(const Type& newItem);
void deleteNode(const Type& deleteItem);
nodeType* begin();
nodeType* end();
linkedListType();
~linkedListType();
linkedListType(const linkedListType& otherList);
const linkedListType& operator= (const linkedListType&);/o
protected:
int count;
nodeType *first;
nodeType *last;
private:
void copyList(const linkedListType& otherList);
};
template
bool linkedListType::isEmptyList() const
{
return (first == NULL);
}
template
linkedListType::linkedListType() //default constructor
{
first = NULL;
last = NULL;
count = 0;
}
template
void linkedListType::destroyList()
{
nodeType *temp; //pointer to deallocate the memory
//occupied by the node
{
temp = first; //set temp to the current node
first = first->link; //advance first to the next node
delete temp; //deallocate the memory occupied by temp
}
last = NULL; //initialize last to NULL; first has already
//been set to NULL by the while loop
count = 0;
}
template
void linkedListType::initializeList()
{
destroyList(); //if the list has any nodes, delete them
}
template
void linkedListType::print() const
{
nodeType *current; //pointer to traverse the list
current = first; //set current so that it points to
//the first node
while (current != NULL) //while more data to print
{
cout info
current = current->link;
}
}//end print
template
int linkedListType::length() const
{
return count;
}
template
Type linkedListType::front() const
{
assert(first != NULL);
return first->info; //return the info of the first node
}//end front
template
Type linkedListType::back() const
{
assert(last != NULL);
return last->info; //return the info of the last node
}//end back
template
nodeType* linkedListType::begin()
{
return first;
}
template
nodeType* linkedListType::end()
{
return last;
}
template
void linkedListType::copyList
(const linkedListType& otherList)
{
nodeType *newNode; //pointer to create a node
nodeType *current; //pointer to traverse the list
if (first != NULL) //if the list is nonempty, make it empty
destroyList();
if (otherList.first == NULL) //otherList is empty
{
first = NULL;
last = NULL;
count = 0;
}
else
{
current = otherList.first; //current points to the
//list to be copied
count = otherList.count;
//copy the first node
first = new nodeType; //create the node
first->info = current->info; //copy the info
first->link = NULL; //set the link field of
//the node to NULL
last = first; //make last point to the
//first node
current = current->link; //make current point to
//the next node
//copy the remaining list
while (current != NULL)
{
newNode = new nodeType; //create a node
newNode->info = current->info; //copy the info
newNode->link = NULL; //set the link of
/ewNode to NULL
last->link = newNode; //attach newNode after last
last = newNode; //make last point to
//the actual last node
current = current->link; //make current point
//to the next node
}//end while
}//end else
}//end copyList
template
linkedListType::~linkedListType() //destructor
{
destroyList();
}
template
linkedListType::linkedListType
(const linkedListType& otherList)
{
first = NULL;
copyList(otherList);
}//end copy constructor
template
const linkedListType& linkedListType::operator=
(const linkedListType& otherList)
{
if (this != &otherList) //avoid self-copy
{
copyList(otherList);
}//end else
return *this;
}
template
bool linkedListType::
search(const Type& searchItem) const
{
nodeType *current; //pointer to traverse the list
bool found = false;
current = first; //set current to point to the first
/ode in the list
while (current != NULL && !found) //search the list
if (current->info == searchItem) //searchItem is found
found = true;
else
current = current->link; //make current point to
//the next node
return found;
}//end search
template
void linkedListType::insertFirst(const Type& newItem)
{
nodeType *newNode; //pointer to create the new node
newNode = new nodeType; //create the new node
newNode->info = newItem; //store the new item in the node
newNode->link = first; //insert newNode before first
first = newNode; //make first point to the
//actual first node
count++; //increment count
if (last == NULL) //if the list was empty, newNode is also
//the last node in the list
last = newNode;
}//end insertFirst
template
void linkedListType::insertLast(const Type& newItem)
{
nodeType *newNode; //pointer to create the new node
newNode = new nodeType; //create the new node
newNode->info = newItem; //store the new item in the node
newNode->link = NULL; //set the link field of newNode
//to NULL
if (first == NULL) //if the list is empty, newNode is
//both the first and last node
{
first = newNode;
last = newNode;
count++; //increment count
}
else //the list is not empty, insert newNode after last
{
last->link = newNode; //insert newNode after last
last = newNode; //make last point to the actual
//last node in the list
count++; //increment count
}
}//end insertLast
template
void linkedListType::deleteNode(const Type& deleteItem)
{
nodeType *current; //pointer to traverse the list
nodeType *trailCurrent; //pointer just before current
bool found;
if (first == NULL) //Case 1; the list is empty
cout
else
{
if (first->info == deleteItem) //Case 2
{
current = first;
first = first->link;
count--;
if (first == NULL) //the list has only one node
last = NULL;
delete current;
}
else //search the list for the node with the given info
{
found = false;
trailCurrent = first; //set trailCurrent to point
//to the first node
current = first->link; //set current to point to
//the second node
while (current != NULL && !found)
{
if (current->info != deleteItem)
{
trailCurrent = current;
current = current-> link;
}
else
found = true;
}//end while
if (found) //Case 3; if found, delete the node
{
trailCurrent->link = current->link;
count--;
if (last == current) /ode to be deleted
//was the last node
last = trailCurrent; //update the value
//of last
delete current; //delete the node from the list
}
else
cout Part 1: Create a Student Class which has the following attributes: Name, ID, and GPA of the students. For this class you need to implement the following: - A default constructor - A set and get functions for all attributes. Functions to overload the stream insertion and extraction operators - A function to overload operator which return true if the two students have the same Name, ID, and GPA otherwise returns false. Part 2: Include the header file of the template class ArrayListType to your program. Include the header file of the template class LinkedListType to your program. - Include the header file of the template class StackType to your program. Part 3: Write the implementation of the following member functions to deal with a linked list: 1. Modify the implementation of the member function "search" so that it returns a pointer to the node if the node info is found in the list and NULL otherwise. 2. Modify the implementation of the member function "print" and rewrite it using recursion. 3. ReversePrinti: this function should use recursion to print the elements of the linkedlist in the reverse order 4. Reverse Print2: this function should use stackType to print the elements of the linkedlist in the reverse order 5. insertAt this function inserts a new node in the location specified in the parameter list. 6. insertAfter: this function adds a new node after the node with the value specified in the parameter list 7. A function to overload [] operator, that returns a pointer to the ih node in the linked list. Part 4 Add the following nonmember functions A nonmember function that read the Linked List info from a text file ("info.txt") - A nonmember function that write the linked List info to a new text file ("new.txt") SeparateList: this function takes a linkedListType of students and two ArrayListType of students; if the student GPA>3 add it to Listl objects otherwise add it to List2, use the following prototype: void Separatelist (LinkedListType * obj. ArrayListType&Listi, ArrayListType&Listi); Part 5: To test your functions, create an object of student type from ArrayListType and two objects of student type from the LinkedListType, then call your function in appropriate order
}//end else
}//end else
}//end deleteNode
#endif // LINKEDLISTTYPE_H_INCLUDED
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
