Question: using namespace std; #include #includellist.h llist::llist ( ) { cout < < . . . in llist constructor... < < endl; Count =
using namespace std;
#include
#include"llist.h
llist::llist
cout in llist constructor..." endl;
Count ;
Front NULL;
Rear NULL;
llist::~llist
cout in llist destructor..." endl;
int x;
whileisEmpty
deleteRearx; It is called to delete all the nodes
PURPOSE: This function checks if the list is empty or not
PARAMETER: None
bool llist::isEmpty
be sure to check all data members
if Front NULL && Rear NULL && Count
return true;
else
return false;
PURPOSE: This function displays all the elements in the list
PARAMETER: None
void llist::displayAll
be sure to display horizontally in with
blanks between elements eg
You MUST use while P NULL loop or you will not get the credit!
Node p Front;
if isEmpty SPECIAL CASE
coutEmpty endl;
else
REGULAR CASE
cout;
whilep NULL
cout pElem ;
p pNext;
cout endl;
PURPOSE: This function adds a node at the end of the end of the list
PARAMETER: NewNum this is the number which we want add it to the list
void llist::addRearelt NewNum
comment the cases
SPECIAL CASE
ifisEmpty
Node p new Node;
Front p;
Rear p;
RearNext NULL;
RearElem NewNum;
Count;
else
REGULAR CASE
RearNext new Node;
Rear RearNext;
RearElem NewNum;
RearNext NULL;
Count;
PURPOSE: This function is going to add an element in the front of the loop!
PARAMETER: NewNum This is the elememt that is to be added to the front of the list.
void llist::addFrontelt NewNum
comment the cases
SPECIAL CASE
ifisEmpty
Node p new Node;
Front p;
Rear p;
RearElem NewNum;
RearNext NULL;
Count;
else
REGULAR CASE
Node p new Node;
pNext Front;
Front p;
FrontElem NewNum;
Count;
PURPOSE: This function deletes the front element of the list.
PARAMETER: OldNum old num is the variable which will store the
value of teh variable before it gets deleted.
void llist::deleteFrontelt& OldNum
comment the cases
ERROR CASE
if isEmpty
throw Underflow;
else
SPECIAL CASE
Node p Front;
if Count
OldNum FrontElem;
delete Front;
Front NULL;
Rear NULL;
Count;
else
REGULAR CASE
OldNum FrontElem;
Node Second;
Second FrontNext;
delete Front;
Front Second;
Count;
PURPOSE: This Function is used to delete the rear number from the list
PARAMETER: OldNum this stores the number in it beforeit gets deleted.
void llist::deleteRearelt& OldNum
comment the cases
ERROR CASE
ifisEmpty
throw Underflow;
else
SPECIAL CASE
ifCount
OldNum FrontElem;
delete Rear;
Front NULL;
Rear NULL;
Count;
REGULAR CASE
else
OldNum Rear Elem;
Node p Front;
whilep Next Rear
p pNext;
delete Rear;
Rear p;
Rear Next NULL;
Count;
OldNum Rear Elem;
Node traversal Front;
whiletraversal Next Rear
traversal traversal Next;
delete Rear;
Rear traversal;
Rear Next NULL;
Count ;
Utility Function to move a local pointer to the Jth node
void llist::moveToint J Node& temp
Note that case client does not test this. But it is neede
for case so make it work perfectly.
for int K ; K J; K
moves temp J times to go to the Jth node and Count is assumed
for int K temp tempNext;
temp tempNext;
harder ones for case and follow
PURPOSE: This function is used to to delete an elememt at the Ith position
PARAMETER: I OldNum I is the position we are passing and
oldNum is the number which passed by reference before it gets
deleted from the list
void llist::deleteIthint I, elt& OldNum
must use moveTo to move local pointers. Be sure to comment to which node you are moving them. Do not forget to set OldNum.
ERROR CASE
ifI Count I
throw OutOfRange;
else
SPECIAL CASE
ifI
deleteFrontOldNum;
else ifI Count
deleteRearOldNum;
else
REGULAR CASE
Node p Front;
Node q Front;
moveToI p;
moveToI q;
OldNum p Next Elem;
delete p Next;
p Next q;
Count;
PURPOSE: This function is used to insert an element at the Ith position of the list
PARAMETER: I, newNum I is the position where the element is
supposed to be inserted whereas newNum is the number which is to
be inserted in the list.
void llist::insertIthint I, elt new
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
