Question: Question 2 Implement the 2 outstanding housekeeping functions: the copy - constructor and the assignment copy - constructor. 1 template 2 class LinkedList { 3
Question Implement the outstanding housekeeping functions: the copyconstructor and the
assignment copyconstructor.
template
class LinkedList
public :
LinkedList ;
LinkedList const LinkedList & obj ;
LinkedList & operator const LinkedList & obj ;
~ LinkedList ;
bool isEmpty const;
const E& front const throw LinkedListEmpty ;
const E& back const throw LinkedListEmpty ;
void addFront const E& e;
void removeFront throw LinkedListEmpty ;
void addBack const E& s;
void removeBack throw LinkedListEmpty ;
friend ostream & operator ostream & out const LinkedList & obj
Node temp obj.head;
iftemp NULL out ; return out ;
out ;
whiletemp NULL
out temp elem;
iftemp next NULL out ;
temp temp next;
out ;
return out;
private :
Node head;
;
Input Main:
int mainvoid
LinkedList myList new LinkedList ;
cout myList endl;
Adding to the front
cout myList isEmpty endl;
myList addFront Gandalf ;
cout myList endl;
myList addFront Aragorn ;
cout myList endl;
myList addFront Legolas ;
cout myList endl;
cout "Front element : t myList front endl;
cout "Back element : t myList back endl;
Removing from the front
myList removeFront ;
cout myList endl;
myList removeFront ;
cout myList endl;
myList removeFront ;
cout myList endl;
Should be able to handle this
myList removeFront ;
Adding to the back
myList addBack Gollum;
cout myList endl;
myList addBack Bilbo Baggins ;
cout myList endl;
myList addBack Saruman ;
cout : myList endl;
LinkedList myList new LinkedList myList ;
cout : myList endl;
LinkedList myList new LinkedList ;
myListmyList;
cout : myList endl;
cout "Front element : t myList front endl;
cout "Back element : t myList back endl;
Removing from the back
myList removeBack ;
cout myList endl;
myList removeBack ;
cout myList endl;
myList removeBack ;
cout myList endl;
Should be able to handle this
myList removeBack ;
cout myList endl;
return ;
Program Output:
Gandalf
AragornGandalf
LegolasAragornGandalf
Front element: Legolas
Back element: Gandalf
AragornGandalf
Gandalf
Removing the front of an empty linked list
Gollum
GollumBilbo Baggins
: GollumBilbo BagginsSaruman
: GollumBilbo BagginsSaruman
: GollumBilbo BagginsSaruman
Front element: Gollum
Back element: Saruman
GollumBilbo Baggins
Gollum
Removing the back of an empty linked list
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
