Question: template class LinkedList : public ListInterface { private: Node * headPtr; / / Pointer to first node in the chain; / / ( contains the
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.
@pre position is the number of the desired node;
position and position itemCount.
@post The node is found and a pointer to it is returned.
@param position The number of the node to locate.
@return A pointer to the node at the given position.
Node getNodeAtint position const;
public:
LinkedList;
LinkedListconst LinkedList& aList;
virtual ~LinkedList;
bool isEmpty const;
int getLength const;
bool insertint newPosition, const ItemType& newEntry;
bool removeint position;
void clear;
@throw PrecondViolatedExcep if position or
position getLength
ItemType getEntryint position const throwPrecondViolatedExcep;
@throw PrecondViolatedExcep if position or
position getLength
ItemType replaceint position, const ItemType& newEntry
throwPrecondViolatedExcep;
; end LinkedList
Question points
Consider a non member function that searches for the position of a given item in a ADT List. Which is the correct implementation among the following answers?
Question options:
a
template
int findconst LinkedList & aList, const ItemType& anItem
for int i ; i aList.getLength; i
if anItem aListi
return i;
end if
end for
return ;
b
template
int findconst LinkedList & aList, const ItemType& anItem
node curPtr headPtr;
int i;
while curPtrNULL && iaList.getLength
ifcurPtrgetItemanItem
return i;
i;
curPtrcurPtrgetNext;
return ;
c
template
int findconst LinkedList & aList, const ItemType& anItem
node curPtr aList.headPtr;
int i;
while curPtrNULL && iitermCount
ifcurPtrgetItemanItem
return i;
i;
curPtrcurPtrgetNext;
return ;
d
template
int findconst LinkedList & aList, const ItemType& anItem
for int i ; i aList.getLength; i
if anItem aList.getEntryi
return i;
end for
return ;
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
