Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with this. Read the files carefully. Points one and two have been marked in the definition of OLList::insert and point three in function
Please help with this. Read the files carefully. Points one
and two have been marked in the definition of OLList::insert and point three in function OLList::remove.
Draw memory diagram when program reached these points for the first time.
Submit your diagrams. Please provide a digital copy of your diagram using a scanner and post it as part of your lab
report on the DL Also make sure the scanned copy of your diagram is clear and readable.
Ex E:
labExE.cpp
ENSF Spring Lab Exercise E
#include
using namespace std;
#include "OLList.h
int main
OLList thelist;
cout "List just after creation: ;
thelist.print;
thelist.insert;
thelist.insert;
thelist.insert;
thelist.insert;
cout "List after some insertions: ;
thelist.print;
thelist.remove;
thelist.remove;
cout "List after some removals: ;
thelist.print;
return ;
OLLIST.h:
OLList.h
ENSF Spring Lab Exercises E and F
#ifndef OLLISTH
#define OLLISTH
typedef int ListItem;
struct Node
ListItem item;
Node next;
;
class OLList
public:
OLList; PROMISES: Creates empty list.
OLListconst OLList& source;
OLList& operator const OLList& rhs;
~OLList;
void insertconst ListItem& itemA;
PROMISES:
A node with a copy of itemA is added in
a way that preserves the nondecreasing
order of items in nodes.
void removeconst ListItem& itemA;
PROMISES:
If no node has an item matching itemA,
list is unchanged.
Otherwise exactly one node with
its item itemA is removed.
void print const;
PROMISES:
Prints items in list on a single line, with commas separating
the items and square brackets marking the ends of the list.
NOTE:
This is different from the print function presented in lectures.
private:
Node headM;
void destroy;
Deallocate all nodes, set headM to zero.
void copyconst OLList& source;
List becomes copy of source.
;
#endif
OLLIST.cpp:
OLList.cpp
ENSF Spring Lab Exercise E and F
#include
#include
using namespace std;
#include "OLList.h
OLList::OLList
: headMnullptr
OLList::OLListconst OLList& source
copysource;
OLList& OLList::operator const OLList& rhs
if this &rhs
destroy;
copyrhs;
return this;
OLList::~OLList
destroy;
void OLList::print const
cout ;
if headM nullptr
cout headMitem;
for const Node p headMnext; p nullptr; p pnext
cout pitem;
cout
;
void OLList::insertconst ListItem& itemA
Node newnode new Node;
newnodeitem itemA;
if headM nullptr itemA headMitem
newnodenext headM;
headM newnode;
point one
else
Node before headM; will point to node in front of new node
Node after headMnext; will be nullptr or point to node after new node
whileafter nullptr && itemA afteritem
before after;
after afternext;
newnodenext after;
beforenext newnode;
point two
void OLList::removeconst ListItem& itemA
if list is empty, do nothing
if headM nullptr itemA headMitem
return;
Node doomednode nullptr;
if itemA headMitem
doomednode headM;
headM headMnext;
else
Node before headM;
Node maybedoomed headMnext;
whilemaybedoomed nullptr && itemA maybedoomeditem
before maybedoomed;
maybedoomed maybedoomednext;
point three
the remaining part of this function is missing. As part of exercise A
students are supposed to complete the rest of the definition of this function.
void OLList::destroy
this function is not properly designed. As part of the exercise A
students are supposed to remove the folloiwng lines and
complete the definition of this helper function.
cout "OLList::destroy was called but isn't ready for use"
program is terminated.
;
headM nullptr;
void OLList::copyconst OLList& source
this function is not properly designed. As part of the exercise A
students are supposed to remove the folloiwng lines and
complete the definition of this helper function.
The only effect of the next line is to tell the compiler
not to generate an "unused argument" warning. Don't leave it
it in y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started