SlideShare a Scribd company logo
1 of 21
Download to read offline
Answer:
Note: LinkedList.cpp is written and driver program main.cpp is also given.
//ListInterface.h
#ifndef _LIST_INTERFACE
#define _LIST_INTERFACE
template
class ListInterface
{
public:
virtual bool isEmpty() const = 0;
virtual int getLength() const = 0;
virtual bool insert(int newPosition, const ItemType& newEntry) = 0;
virtual bool remove(int position) = 0;
virtual void clear() = 0;
virtual ItemType getEntry(int position) const = 0;
virtual void replace(int position, const ItemType& newEntry) = 0;
}; // end ListInterface
#endif
//Node.h
#ifndef NODE_
#define NODE_
template
class Node
{
private:
ItemType item; // A data item
Node* next; // Pointer to next node
public:
Node();
Node(const ItemType& anItem);
Node(const ItemType& anItem, Node* nextNodePtr);
void setItem(const ItemType& anItem);
void setNext(Node* nextNodePtr);
ItemType getItem() const ;
Node* getNext() const ;
}; // end Node
#endif
//Node.cpp
#include "Node.h"
template
Node::Node() : next(nullptr)
{
} // end default constructor
template
Node::Node(const ItemType& anItem) : item(anItem), next(nullptr)
{
} // end constructor
template
Node::Node(const ItemType& anItem, Node* nextNodePtr) :
item(anItem), next(nextNodePtr)
{
} // end constructor
template
void Node::setItem(const ItemType& anItem)
{
item = anItem;
} // end setItem
template
void Node::setNext(Node* nextNodePtr)
{
next = nextNodePtr;
} // end setNext
template
ItemType Node::getItem() const
{
return item;
} // end getItem
template
Node* Node::getNext() const
{
return next;
} // end getNext
//PrecondViolatedExcept.h
#ifndef PRECOND_VIOLATED_EXCEPT_
#define PRECOND_VIOLATED_EXCEPT_
#include
#include
class PrecondViolatedExcept : public std::logic_error
{
public:
PrecondViolatedExcept(const std::string& message = "");
}; // end PrecondViolatedExcept
#endif
//PrecondViolatedExcept.cpp
#include "PrecondViolatedExcept.h"
PrecondViolatedExcept::PrecondViolatedExcept(const std::string& message)
: std::logic_error("Precondition Violated Exception: " + message)
{
} // end constructor
//LinkedList.h
#ifndef LINKED_LIST_
#define LINKED_LIST_
#include "ListInterface.h"
#include "Node.h"
#include
#include "PrecondViolatedExcept.h"
template
class LinkedList : public ListInterface
{
private:
Node* headPtr; // Pointer to first node in the chain;
// (contains the first entry in the list)
int itemCount; // Current count of list items
// Locates a specified node in this linked list.
Node* getNodeAt(int position) const;
public:
LinkedList();
LinkedList(const LinkedList& aList);
virtual ~LinkedList();
bool isEmpty() const;
int getLength() const;
bool insert(int newPosition, const ItemType& newEntry);
bool remove(int position);
void clear();
ItemType getEntry(int position) const;
void replace(int position, const ItemType& newEntry);
}; // end LinkedList
#endif
//LinkedList.cpp
#include "LinkedList.h"
#include
#include
#include
#include
//Default constructor
template
LinkedList::LinkedList() : headPtr(nullptr), itemCount(0)
{
}
//Copy constructor
template
LinkedList::LinkedList(const LinkedList& aList)
{
Node* aListheadPtr = aList.headPtr;
itemCount=aList.itemCount;
//Check given list is empty
if (aListheadPtr == nullptr)
//If aList is empty then set headPtr to null.
headPtr = nullptr;
else
{
//copying first node
headPtr = new Node();
headPtr->setItem(aListheadPtr->getItem());
//*this headPtr
Node* myListHeadPtr = headPtr;
//Get next node in the aList
aListheadPtr = aListheadPtr->getNext();
//Copy all the items
while (aListheadPtr != nullptr)
{
// Get from aList
ItemType nxtItm = aListheadPtr->getItem();
// Create new node for nxtItm
Node* nNodePointer = new Node(nxtItm);
// place new node
myListHeadPtr->setNext(nNodePointer);
// Increment last pointer
myListHeadPtr = myListHeadPtr->getNext();
// Move to next element in aList
aListheadPtr = aListheadPtr->getNext();
}
//Set end
myListHeadPtr->setNext(nullptr);
}
}
//Destructor that destroy the object
template
LinkedList::~LinkedList()
{
//Clear all elements
clear();
//Reset itemCount
itemCount=0;
}
//Function to check *this is empty.
//It return 0 if list is empty, otherwise 1
template
bool LinkedList::isEmpty() const
{
//Check itemCount is 0.
if(itemCount==0)
//Return true
return true;
//Return false
return false;
}
//Function return the length of the list *this
template
int LinkedList::getLength() const
{
//Return the itemCount
return itemCount;
}
//Function to insert the given newEntry at the said position
template
bool LinkedList::insert(int newPosition, const ItemType& newEntry)
{
//Check position is available
bool isPossInsert = false;
if((newPosition <= itemCount + 1) && (newPosition >= 1))
//Set possible to insert to true.
isPossInsert = true;
//If possible to insert then
if (isPossInsert)
{
//Create a nNodePointer for newEntry
Node* nNodePointer = new Node(newEntry);
// Check if newPosition is 1
if (newPosition == 1)
{
// Insert newEntry at start
nNodePointer->setNext(headPtr);
//set the headPtr
headPtr = nNodePointer;
}
//Otherwise insert the node in the middle
else
{
//Find the previous node
Node* myPrePtrr = getNodeAt(newPosition - 1);
//Insert nNodePointer after myPrePtrr
nNodePointer->setNext(myPrePtrr->getNext());
myPrePtrr->setNext(nNodePointer);
}
//increment the item count
itemCount++;
}
//Return the isPossInsert
return isPossInsert;
}
//Function to remove the node at the position
template
bool LinkedList::remove(int position)
{
//Check possible to remove node at "position"
bool isPossRemove =false;
if((position <= itemCount) && (position >= 1))
isPossRemove =true;
//If possible to remove
if (isPossRemove)
{
//Temp node
Node* myCurrPtrr = nullptr;
//Check first node needed to be deleted
if (position == 1)
{
// Remove the 1st node
myCurrPtrr = headPtr;
//Reset the headPtrS
headPtr = headPtr->getNext();
}
//Otherwise, node is to deleted in somewhere else
else
{
int ppId=position - 1
// Find prev node
Node* myPrePtrr = getNodeAt(ppId);
// Get the node to be deleted
myCurrPtrr = myPrePtrr->getNext();
//Reset the node connection
myPrePtrr->setNext(myCurrPtrr->getNext());
}
// set the curr node
myCurrPtrr->setNext(nullptr);
//Delete node
delete myCurrPtrr;
myCurrPtrr = nullptr;
//Decrement the item count.
itemCount--;
}
//return isPossRemove
return isPossRemove;
}
//Function to empty the *this
template
void LinkedList::clear()
{
//Until elements in the list
while (!isEmpty())
//Remove the element
remove(1);
}
//Function to item at the position
template
ItemType LinkedList::getEntry(int position) const throw(PrecondViolatedExcept)
{
// Check possibility to retrieve item
bool isPossRetrieve = (position >= 1) && (position <= itemCount);
//if possible to get item then
if (isPossRetrieve)
{
//Get node at the "position"
Node* nndePointr = getNodeAt(position);
//Return the item
return nndePointr->getItem();
}
else
{
//Throw a PrecondViolatedExcept exception
throw(PrecondViolatedExcept("List is empty or invalid position"));
}
}
//Function to replace item at position with newEntry
template
void LinkedList::replace(int position, const ItemType& newEntry)
throw(PrecondViolatedExcept)
{
// Check possibility to replace
bool isPossReplace = (position >= 1) && (position <= itemCount);
//If possible to replace
if (isPossReplace)
{
//Get node at the "position"
Node* nndePointr = getNodeAt(position);
//Set item to newEntry
nndePointr->setItem(newEntry);
}
else
{
//Throw a PrecondViolatedExcept exception
throw(PrecondViolatedExcept("Position is not valid"));
}
}
//Function to get node at specified position
template
Node* LinkedList::getNodeAt(int position) const
{
//Assert the position
assert( (position >= 1) && (position <= itemCount) );
// get headPtr
Node* myCurrPtrr = headPtr;
//Move to the specified position
for (int kk = 1; kk < position; kk++)
//Move to next node
myCurrPtrr = myCurrPtrr->getNext();
//Return the node
return myCurrPtrr;
}
//main.cpp
#include
#include
#include "ListInterface.h"
#include "Node.h"
#include "PrecondViolatedExcept.h"
#include "LinkedList.h"
using namespace std;
int main()
{
LinkedList ll;
int a=10;
int b=20;int c=15;
ll.insert(0,a);
ll.insert(2,b);
ll.insert(1,c);
cout<<"List length:"<
Solution
Answer:
Note: LinkedList.cpp is written and driver program main.cpp is also given.
//ListInterface.h
#ifndef _LIST_INTERFACE
#define _LIST_INTERFACE
template
class ListInterface
{
public:
virtual bool isEmpty() const = 0;
virtual int getLength() const = 0;
virtual bool insert(int newPosition, const ItemType& newEntry) = 0;
virtual bool remove(int position) = 0;
virtual void clear() = 0;
virtual ItemType getEntry(int position) const = 0;
virtual void replace(int position, const ItemType& newEntry) = 0;
}; // end ListInterface
#endif
//Node.h
#ifndef NODE_
#define NODE_
template
class Node
{
private:
ItemType item; // A data item
Node* next; // Pointer to next node
public:
Node();
Node(const ItemType& anItem);
Node(const ItemType& anItem, Node* nextNodePtr);
void setItem(const ItemType& anItem);
void setNext(Node* nextNodePtr);
ItemType getItem() const ;
Node* getNext() const ;
}; // end Node
#endif
//Node.cpp
#include "Node.h"
template
Node::Node() : next(nullptr)
{
} // end default constructor
template
Node::Node(const ItemType& anItem) : item(anItem), next(nullptr)
{
} // end constructor
template
Node::Node(const ItemType& anItem, Node* nextNodePtr) :
item(anItem), next(nextNodePtr)
{
} // end constructor
template
void Node::setItem(const ItemType& anItem)
{
item = anItem;
} // end setItem
template
void Node::setNext(Node* nextNodePtr)
{
next = nextNodePtr;
} // end setNext
template
ItemType Node::getItem() const
{
return item;
} // end getItem
template
Node* Node::getNext() const
{
return next;
} // end getNext
//PrecondViolatedExcept.h
#ifndef PRECOND_VIOLATED_EXCEPT_
#define PRECOND_VIOLATED_EXCEPT_
#include
#include
class PrecondViolatedExcept : public std::logic_error
{
public:
PrecondViolatedExcept(const std::string& message = "");
}; // end PrecondViolatedExcept
#endif
//PrecondViolatedExcept.cpp
#include "PrecondViolatedExcept.h"
PrecondViolatedExcept::PrecondViolatedExcept(const std::string& message)
: std::logic_error("Precondition Violated Exception: " + message)
{
} // end constructor
//LinkedList.h
#ifndef LINKED_LIST_
#define LINKED_LIST_
#include "ListInterface.h"
#include "Node.h"
#include
#include "PrecondViolatedExcept.h"
template
class LinkedList : public ListInterface
{
private:
Node* headPtr; // Pointer to first node in the chain;
// (contains the first entry in the list)
int itemCount; // Current count of list items
// Locates a specified node in this linked list.
Node* getNodeAt(int position) const;
public:
LinkedList();
LinkedList(const LinkedList& aList);
virtual ~LinkedList();
bool isEmpty() const;
int getLength() const;
bool insert(int newPosition, const ItemType& newEntry);
bool remove(int position);
void clear();
ItemType getEntry(int position) const;
void replace(int position, const ItemType& newEntry);
}; // end LinkedList
#endif
//LinkedList.cpp
#include "LinkedList.h"
#include
#include
#include
#include
//Default constructor
template
LinkedList::LinkedList() : headPtr(nullptr), itemCount(0)
{
}
//Copy constructor
template
LinkedList::LinkedList(const LinkedList& aList)
{
Node* aListheadPtr = aList.headPtr;
itemCount=aList.itemCount;
//Check given list is empty
if (aListheadPtr == nullptr)
//If aList is empty then set headPtr to null.
headPtr = nullptr;
else
{
//copying first node
headPtr = new Node();
headPtr->setItem(aListheadPtr->getItem());
//*this headPtr
Node* myListHeadPtr = headPtr;
//Get next node in the aList
aListheadPtr = aListheadPtr->getNext();
//Copy all the items
while (aListheadPtr != nullptr)
{
// Get from aList
ItemType nxtItm = aListheadPtr->getItem();
// Create new node for nxtItm
Node* nNodePointer = new Node(nxtItm);
// place new node
myListHeadPtr->setNext(nNodePointer);
// Increment last pointer
myListHeadPtr = myListHeadPtr->getNext();
// Move to next element in aList
aListheadPtr = aListheadPtr->getNext();
}
//Set end
myListHeadPtr->setNext(nullptr);
}
}
//Destructor that destroy the object
template
LinkedList::~LinkedList()
{
//Clear all elements
clear();
//Reset itemCount
itemCount=0;
}
//Function to check *this is empty.
//It return 0 if list is empty, otherwise 1
template
bool LinkedList::isEmpty() const
{
//Check itemCount is 0.
if(itemCount==0)
//Return true
return true;
//Return false
return false;
}
//Function return the length of the list *this
template
int LinkedList::getLength() const
{
//Return the itemCount
return itemCount;
}
//Function to insert the given newEntry at the said position
template
bool LinkedList::insert(int newPosition, const ItemType& newEntry)
{
//Check position is available
bool isPossInsert = false;
if((newPosition <= itemCount + 1) && (newPosition >= 1))
//Set possible to insert to true.
isPossInsert = true;
//If possible to insert then
if (isPossInsert)
{
//Create a nNodePointer for newEntry
Node* nNodePointer = new Node(newEntry);
// Check if newPosition is 1
if (newPosition == 1)
{
// Insert newEntry at start
nNodePointer->setNext(headPtr);
//set the headPtr
headPtr = nNodePointer;
}
//Otherwise insert the node in the middle
else
{
//Find the previous node
Node* myPrePtrr = getNodeAt(newPosition - 1);
//Insert nNodePointer after myPrePtrr
nNodePointer->setNext(myPrePtrr->getNext());
myPrePtrr->setNext(nNodePointer);
}
//increment the item count
itemCount++;
}
//Return the isPossInsert
return isPossInsert;
}
//Function to remove the node at the position
template
bool LinkedList::remove(int position)
{
//Check possible to remove node at "position"
bool isPossRemove =false;
if((position <= itemCount) && (position >= 1))
isPossRemove =true;
//If possible to remove
if (isPossRemove)
{
//Temp node
Node* myCurrPtrr = nullptr;
//Check first node needed to be deleted
if (position == 1)
{
// Remove the 1st node
myCurrPtrr = headPtr;
//Reset the headPtrS
headPtr = headPtr->getNext();
}
//Otherwise, node is to deleted in somewhere else
else
{
int ppId=position - 1
// Find prev node
Node* myPrePtrr = getNodeAt(ppId);
// Get the node to be deleted
myCurrPtrr = myPrePtrr->getNext();
//Reset the node connection
myPrePtrr->setNext(myCurrPtrr->getNext());
}
// set the curr node
myCurrPtrr->setNext(nullptr);
//Delete node
delete myCurrPtrr;
myCurrPtrr = nullptr;
//Decrement the item count.
itemCount--;
}
//return isPossRemove
return isPossRemove;
}
//Function to empty the *this
template
void LinkedList::clear()
{
//Until elements in the list
while (!isEmpty())
//Remove the element
remove(1);
}
//Function to item at the position
template
ItemType LinkedList::getEntry(int position) const throw(PrecondViolatedExcept)
{
// Check possibility to retrieve item
bool isPossRetrieve = (position >= 1) && (position <= itemCount);
//if possible to get item then
if (isPossRetrieve)
{
//Get node at the "position"
Node* nndePointr = getNodeAt(position);
//Return the item
return nndePointr->getItem();
}
else
{
//Throw a PrecondViolatedExcept exception
throw(PrecondViolatedExcept("List is empty or invalid position"));
}
}
//Function to replace item at position with newEntry
template
void LinkedList::replace(int position, const ItemType& newEntry)
throw(PrecondViolatedExcept)
{
// Check possibility to replace
bool isPossReplace = (position >= 1) && (position <= itemCount);
//If possible to replace
if (isPossReplace)
{
//Get node at the "position"
Node* nndePointr = getNodeAt(position);
//Set item to newEntry
nndePointr->setItem(newEntry);
}
else
{
//Throw a PrecondViolatedExcept exception
throw(PrecondViolatedExcept("Position is not valid"));
}
}
//Function to get node at specified position
template
Node* LinkedList::getNodeAt(int position) const
{
//Assert the position
assert( (position >= 1) && (position <= itemCount) );
// get headPtr
Node* myCurrPtrr = headPtr;
//Move to the specified position
for (int kk = 1; kk < position; kk++)
//Move to next node
myCurrPtrr = myCurrPtrr->getNext();
//Return the node
return myCurrPtrr;
}
//main.cpp
#include
#include
#include "ListInterface.h"
#include "Node.h"
#include "PrecondViolatedExcept.h"
#include "LinkedList.h"
using namespace std;
int main()
{
LinkedList ll;
int a=10;
int b=20;int c=15;
ll.insert(0,a);
ll.insert(2,b);
ll.insert(1,c);
cout<<"List length:"<

More Related Content

Similar to AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf

#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdfKUNALHARCHANDANI1
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdffantoosh1
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdfharihelectronicspune
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfabiwarmaa
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Change the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdfChange the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdffatoryoutlets
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdfacmefit
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 

Similar to AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf (20)

#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Change the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdfChange the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdf
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 

More from anwarsadath111

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdfanwarsadath111
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdfanwarsadath111
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfanwarsadath111
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfanwarsadath111
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfanwarsadath111
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdfanwarsadath111
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfanwarsadath111
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfanwarsadath111
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfanwarsadath111
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfanwarsadath111
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfanwarsadath111
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfanwarsadath111
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfanwarsadath111
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfanwarsadath111
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfanwarsadath111
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfanwarsadath111
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdfanwarsadath111
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdfanwarsadath111
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 

More from anwarsadath111 (20)

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdf
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdf
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdf
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdf
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdf
 
SF4SolutionSF4.pdf
SF4SolutionSF4.pdfSF4SolutionSF4.pdf
SF4SolutionSF4.pdf
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdf
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdf
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 

Recently uploaded

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf

  • 1. Answer: Note: LinkedList.cpp is written and driver program main.cpp is also given. //ListInterface.h #ifndef _LIST_INTERFACE #define _LIST_INTERFACE template class ListInterface { public: virtual bool isEmpty() const = 0; virtual int getLength() const = 0; virtual bool insert(int newPosition, const ItemType& newEntry) = 0; virtual bool remove(int position) = 0; virtual void clear() = 0; virtual ItemType getEntry(int position) const = 0; virtual void replace(int position, const ItemType& newEntry) = 0; }; // end ListInterface #endif //Node.h #ifndef NODE_ #define NODE_ template class Node { private: ItemType item; // A data item Node* next; // Pointer to next node public: Node(); Node(const ItemType& anItem); Node(const ItemType& anItem, Node* nextNodePtr); void setItem(const ItemType& anItem); void setNext(Node* nextNodePtr); ItemType getItem() const ; Node* getNext() const ;
  • 2. }; // end Node #endif //Node.cpp #include "Node.h" template Node::Node() : next(nullptr) { } // end default constructor template Node::Node(const ItemType& anItem) : item(anItem), next(nullptr) { } // end constructor template Node::Node(const ItemType& anItem, Node* nextNodePtr) : item(anItem), next(nextNodePtr) { } // end constructor template void Node::setItem(const ItemType& anItem) { item = anItem; } // end setItem template void Node::setNext(Node* nextNodePtr) { next = nextNodePtr; } // end setNext template ItemType Node::getItem() const { return item; } // end getItem template Node* Node::getNext() const { return next;
  • 3. } // end getNext //PrecondViolatedExcept.h #ifndef PRECOND_VIOLATED_EXCEPT_ #define PRECOND_VIOLATED_EXCEPT_ #include #include class PrecondViolatedExcept : public std::logic_error { public: PrecondViolatedExcept(const std::string& message = ""); }; // end PrecondViolatedExcept #endif //PrecondViolatedExcept.cpp #include "PrecondViolatedExcept.h" PrecondViolatedExcept::PrecondViolatedExcept(const std::string& message) : std::logic_error("Precondition Violated Exception: " + message) { } // end constructor //LinkedList.h #ifndef LINKED_LIST_ #define LINKED_LIST_ #include "ListInterface.h" #include "Node.h" #include #include "PrecondViolatedExcept.h" template class LinkedList : public ListInterface { private: Node* headPtr; // Pointer to first node in the chain; // (contains the first entry in the list) int itemCount; // Current count of list items // Locates a specified node in this linked list. Node* getNodeAt(int position) const; public: LinkedList();
  • 4. LinkedList(const LinkedList& aList); virtual ~LinkedList(); bool isEmpty() const; int getLength() const; bool insert(int newPosition, const ItemType& newEntry); bool remove(int position); void clear(); ItemType getEntry(int position) const; void replace(int position, const ItemType& newEntry); }; // end LinkedList #endif //LinkedList.cpp #include "LinkedList.h" #include #include #include #include //Default constructor template LinkedList::LinkedList() : headPtr(nullptr), itemCount(0) { } //Copy constructor template LinkedList::LinkedList(const LinkedList& aList) { Node* aListheadPtr = aList.headPtr; itemCount=aList.itemCount; //Check given list is empty if (aListheadPtr == nullptr) //If aList is empty then set headPtr to null. headPtr = nullptr; else { //copying first node headPtr = new Node();
  • 5. headPtr->setItem(aListheadPtr->getItem()); //*this headPtr Node* myListHeadPtr = headPtr; //Get next node in the aList aListheadPtr = aListheadPtr->getNext(); //Copy all the items while (aListheadPtr != nullptr) { // Get from aList ItemType nxtItm = aListheadPtr->getItem(); // Create new node for nxtItm Node* nNodePointer = new Node(nxtItm); // place new node myListHeadPtr->setNext(nNodePointer); // Increment last pointer myListHeadPtr = myListHeadPtr->getNext(); // Move to next element in aList aListheadPtr = aListheadPtr->getNext(); } //Set end myListHeadPtr->setNext(nullptr); } } //Destructor that destroy the object template LinkedList::~LinkedList() { //Clear all elements clear(); //Reset itemCount itemCount=0;
  • 6. } //Function to check *this is empty. //It return 0 if list is empty, otherwise 1 template bool LinkedList::isEmpty() const { //Check itemCount is 0. if(itemCount==0) //Return true return true; //Return false return false; } //Function return the length of the list *this template int LinkedList::getLength() const { //Return the itemCount return itemCount; } //Function to insert the given newEntry at the said position template bool LinkedList::insert(int newPosition, const ItemType& newEntry) { //Check position is available bool isPossInsert = false; if((newPosition <= itemCount + 1) && (newPosition >= 1)) //Set possible to insert to true. isPossInsert = true; //If possible to insert then if (isPossInsert) { //Create a nNodePointer for newEntry Node* nNodePointer = new Node(newEntry); // Check if newPosition is 1
  • 7. if (newPosition == 1) { // Insert newEntry at start nNodePointer->setNext(headPtr); //set the headPtr headPtr = nNodePointer; } //Otherwise insert the node in the middle else { //Find the previous node Node* myPrePtrr = getNodeAt(newPosition - 1); //Insert nNodePointer after myPrePtrr nNodePointer->setNext(myPrePtrr->getNext()); myPrePtrr->setNext(nNodePointer); } //increment the item count itemCount++; } //Return the isPossInsert return isPossInsert; } //Function to remove the node at the position template bool LinkedList::remove(int position) { //Check possible to remove node at "position" bool isPossRemove =false; if((position <= itemCount) && (position >= 1)) isPossRemove =true; //If possible to remove if (isPossRemove) { //Temp node Node* myCurrPtrr = nullptr;
  • 8. //Check first node needed to be deleted if (position == 1) { // Remove the 1st node myCurrPtrr = headPtr; //Reset the headPtrS headPtr = headPtr->getNext(); } //Otherwise, node is to deleted in somewhere else else { int ppId=position - 1 // Find prev node Node* myPrePtrr = getNodeAt(ppId); // Get the node to be deleted myCurrPtrr = myPrePtrr->getNext(); //Reset the node connection myPrePtrr->setNext(myCurrPtrr->getNext()); } // set the curr node myCurrPtrr->setNext(nullptr); //Delete node delete myCurrPtrr; myCurrPtrr = nullptr; //Decrement the item count. itemCount--; } //return isPossRemove return isPossRemove; } //Function to empty the *this template void LinkedList::clear()
  • 9. { //Until elements in the list while (!isEmpty()) //Remove the element remove(1); } //Function to item at the position template ItemType LinkedList::getEntry(int position) const throw(PrecondViolatedExcept) { // Check possibility to retrieve item bool isPossRetrieve = (position >= 1) && (position <= itemCount); //if possible to get item then if (isPossRetrieve) { //Get node at the "position" Node* nndePointr = getNodeAt(position); //Return the item return nndePointr->getItem(); } else { //Throw a PrecondViolatedExcept exception throw(PrecondViolatedExcept("List is empty or invalid position")); } } //Function to replace item at position with newEntry template void LinkedList::replace(int position, const ItemType& newEntry) throw(PrecondViolatedExcept) { // Check possibility to replace bool isPossReplace = (position >= 1) && (position <= itemCount); //If possible to replace if (isPossReplace) {
  • 10. //Get node at the "position" Node* nndePointr = getNodeAt(position); //Set item to newEntry nndePointr->setItem(newEntry); } else { //Throw a PrecondViolatedExcept exception throw(PrecondViolatedExcept("Position is not valid")); } } //Function to get node at specified position template Node* LinkedList::getNodeAt(int position) const { //Assert the position assert( (position >= 1) && (position <= itemCount) ); // get headPtr Node* myCurrPtrr = headPtr; //Move to the specified position for (int kk = 1; kk < position; kk++) //Move to next node myCurrPtrr = myCurrPtrr->getNext(); //Return the node return myCurrPtrr; } //main.cpp #include #include #include "ListInterface.h" #include "Node.h" #include "PrecondViolatedExcept.h" #include "LinkedList.h" using namespace std; int main() {
  • 11. LinkedList ll; int a=10; int b=20;int c=15; ll.insert(0,a); ll.insert(2,b); ll.insert(1,c); cout<<"List length:"< Solution Answer: Note: LinkedList.cpp is written and driver program main.cpp is also given. //ListInterface.h #ifndef _LIST_INTERFACE #define _LIST_INTERFACE template class ListInterface { public: virtual bool isEmpty() const = 0; virtual int getLength() const = 0; virtual bool insert(int newPosition, const ItemType& newEntry) = 0; virtual bool remove(int position) = 0; virtual void clear() = 0; virtual ItemType getEntry(int position) const = 0; virtual void replace(int position, const ItemType& newEntry) = 0; }; // end ListInterface #endif //Node.h #ifndef NODE_ #define NODE_ template class Node { private: ItemType item; // A data item
  • 12. Node* next; // Pointer to next node public: Node(); Node(const ItemType& anItem); Node(const ItemType& anItem, Node* nextNodePtr); void setItem(const ItemType& anItem); void setNext(Node* nextNodePtr); ItemType getItem() const ; Node* getNext() const ; }; // end Node #endif //Node.cpp #include "Node.h" template Node::Node() : next(nullptr) { } // end default constructor template Node::Node(const ItemType& anItem) : item(anItem), next(nullptr) { } // end constructor template Node::Node(const ItemType& anItem, Node* nextNodePtr) : item(anItem), next(nextNodePtr) { } // end constructor template void Node::setItem(const ItemType& anItem) { item = anItem; } // end setItem template void Node::setNext(Node* nextNodePtr) { next = nextNodePtr; } // end setNext
  • 13. template ItemType Node::getItem() const { return item; } // end getItem template Node* Node::getNext() const { return next; } // end getNext //PrecondViolatedExcept.h #ifndef PRECOND_VIOLATED_EXCEPT_ #define PRECOND_VIOLATED_EXCEPT_ #include #include class PrecondViolatedExcept : public std::logic_error { public: PrecondViolatedExcept(const std::string& message = ""); }; // end PrecondViolatedExcept #endif //PrecondViolatedExcept.cpp #include "PrecondViolatedExcept.h" PrecondViolatedExcept::PrecondViolatedExcept(const std::string& message) : std::logic_error("Precondition Violated Exception: " + message) { } // end constructor //LinkedList.h #ifndef LINKED_LIST_ #define LINKED_LIST_ #include "ListInterface.h" #include "Node.h" #include #include "PrecondViolatedExcept.h" template class LinkedList : public ListInterface
  • 14. { private: Node* headPtr; // Pointer to first node in the chain; // (contains the first entry in the list) int itemCount; // Current count of list items // Locates a specified node in this linked list. Node* getNodeAt(int position) const; public: LinkedList(); LinkedList(const LinkedList& aList); virtual ~LinkedList(); bool isEmpty() const; int getLength() const; bool insert(int newPosition, const ItemType& newEntry); bool remove(int position); void clear(); ItemType getEntry(int position) const; void replace(int position, const ItemType& newEntry); }; // end LinkedList #endif //LinkedList.cpp #include "LinkedList.h" #include #include #include #include //Default constructor template LinkedList::LinkedList() : headPtr(nullptr), itemCount(0) { } //Copy constructor template LinkedList::LinkedList(const LinkedList& aList) { Node* aListheadPtr = aList.headPtr;
  • 15. itemCount=aList.itemCount; //Check given list is empty if (aListheadPtr == nullptr) //If aList is empty then set headPtr to null. headPtr = nullptr; else { //copying first node headPtr = new Node(); headPtr->setItem(aListheadPtr->getItem()); //*this headPtr Node* myListHeadPtr = headPtr; //Get next node in the aList aListheadPtr = aListheadPtr->getNext(); //Copy all the items while (aListheadPtr != nullptr) { // Get from aList ItemType nxtItm = aListheadPtr->getItem(); // Create new node for nxtItm Node* nNodePointer = new Node(nxtItm); // place new node myListHeadPtr->setNext(nNodePointer); // Increment last pointer myListHeadPtr = myListHeadPtr->getNext(); // Move to next element in aList aListheadPtr = aListheadPtr->getNext(); } //Set end myListHeadPtr->setNext(nullptr); }
  • 16. } //Destructor that destroy the object template LinkedList::~LinkedList() { //Clear all elements clear(); //Reset itemCount itemCount=0; } //Function to check *this is empty. //It return 0 if list is empty, otherwise 1 template bool LinkedList::isEmpty() const { //Check itemCount is 0. if(itemCount==0) //Return true return true; //Return false return false; } //Function return the length of the list *this template int LinkedList::getLength() const { //Return the itemCount return itemCount; } //Function to insert the given newEntry at the said position template bool LinkedList::insert(int newPosition, const ItemType& newEntry) { //Check position is available bool isPossInsert = false; if((newPosition <= itemCount + 1) && (newPosition >= 1))
  • 17. //Set possible to insert to true. isPossInsert = true; //If possible to insert then if (isPossInsert) { //Create a nNodePointer for newEntry Node* nNodePointer = new Node(newEntry); // Check if newPosition is 1 if (newPosition == 1) { // Insert newEntry at start nNodePointer->setNext(headPtr); //set the headPtr headPtr = nNodePointer; } //Otherwise insert the node in the middle else { //Find the previous node Node* myPrePtrr = getNodeAt(newPosition - 1); //Insert nNodePointer after myPrePtrr nNodePointer->setNext(myPrePtrr->getNext()); myPrePtrr->setNext(nNodePointer); } //increment the item count itemCount++; } //Return the isPossInsert return isPossInsert; } //Function to remove the node at the position template bool LinkedList::remove(int position) {
  • 18. //Check possible to remove node at "position" bool isPossRemove =false; if((position <= itemCount) && (position >= 1)) isPossRemove =true; //If possible to remove if (isPossRemove) { //Temp node Node* myCurrPtrr = nullptr; //Check first node needed to be deleted if (position == 1) { // Remove the 1st node myCurrPtrr = headPtr; //Reset the headPtrS headPtr = headPtr->getNext(); } //Otherwise, node is to deleted in somewhere else else { int ppId=position - 1 // Find prev node Node* myPrePtrr = getNodeAt(ppId); // Get the node to be deleted myCurrPtrr = myPrePtrr->getNext(); //Reset the node connection myPrePtrr->setNext(myCurrPtrr->getNext()); } // set the curr node myCurrPtrr->setNext(nullptr); //Delete node delete myCurrPtrr; myCurrPtrr = nullptr;
  • 19. //Decrement the item count. itemCount--; } //return isPossRemove return isPossRemove; } //Function to empty the *this template void LinkedList::clear() { //Until elements in the list while (!isEmpty()) //Remove the element remove(1); } //Function to item at the position template ItemType LinkedList::getEntry(int position) const throw(PrecondViolatedExcept) { // Check possibility to retrieve item bool isPossRetrieve = (position >= 1) && (position <= itemCount); //if possible to get item then if (isPossRetrieve) { //Get node at the "position" Node* nndePointr = getNodeAt(position); //Return the item return nndePointr->getItem(); } else { //Throw a PrecondViolatedExcept exception throw(PrecondViolatedExcept("List is empty or invalid position")); } } //Function to replace item at position with newEntry
  • 20. template void LinkedList::replace(int position, const ItemType& newEntry) throw(PrecondViolatedExcept) { // Check possibility to replace bool isPossReplace = (position >= 1) && (position <= itemCount); //If possible to replace if (isPossReplace) { //Get node at the "position" Node* nndePointr = getNodeAt(position); //Set item to newEntry nndePointr->setItem(newEntry); } else { //Throw a PrecondViolatedExcept exception throw(PrecondViolatedExcept("Position is not valid")); } } //Function to get node at specified position template Node* LinkedList::getNodeAt(int position) const { //Assert the position assert( (position >= 1) && (position <= itemCount) ); // get headPtr Node* myCurrPtrr = headPtr; //Move to the specified position for (int kk = 1; kk < position; kk++) //Move to next node myCurrPtrr = myCurrPtrr->getNext(); //Return the node return myCurrPtrr; } //main.cpp
  • 21. #include #include #include "ListInterface.h" #include "Node.h" #include "PrecondViolatedExcept.h" #include "LinkedList.h" using namespace std; int main() { LinkedList ll; int a=10; int b=20;int c=15; ll.insert(0,a); ll.insert(2,b); ll.insert(1,c); cout<<"List length:"<