Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete list.cpp in c++ //Use the provided text to help create llist.cpp //based on Yoshii CS311 Notes-6A //- Make sure PURPOSE and PARAMETER comments are

complete list.cpp in c++

//Use the provided text to help create llist.cpp

//based on Yoshii CS311 Notes-6A

//- Make sure PURPOSE and PARAMETER comments are given

//- Make sure all if-then-else are commented describing which case it i//INSTRUCTION:

s

//- Make sure all local variables are described fully with their purposes

//EMACS HINT:

// control-K cuts and control-Y pastes

// Esc X replace-str does string replacements

// Esc > goes to the end of the file; Esc < to the beginning

// Tab on each line will indent perfectly for C++

// ====================================================

//HW#: HW3P1 llist

//Your name: **

//Complier: **

//File type: llist implementation file

//=====================================================

using namespace std;

#include

#include"llist.h"

Constructor

- initialize Front and Rear to be NULL and Count = 0.

- This does not create any node. The new list is empty.

Destructor

- while the list is not empty, call deleteFront repeatedly to delete all nodes.

- Please place a cout in this function "calling the llist desctructor."

bool llist::isEmpty()

- return true if Front and Rear are both pointing to NULL and Count is 0.

- (all 3 conditions must be checked)

void llist::displayAll()

- Special case: if the list is empty, display [ empty ] ).

- Regular:

displays each element of the list horizontally starting from Front in [ ].

void llist::addRear(el_t NewNum)

2 cases:

- Special case: if this is going to be the very first node, you must

create a new node and make Front and Rear point to it. Place NewNum and

Count is updated.

- Regular: adds a new node at the rear and puts NewNum in the Elem field

of this new node. Count is updated.

Regular case:

Rear->Next = new Node;

Rear = Rear->Next;

Rear->Elem = NewNum;

Rear->Next = NULL;

void llist::addFront(el_t NewNum)

2 cases:

- Special case: if this is going to be the very first node, you must

create a new node and make Front and Rear point to it. Place NewNum and

Count is updated.

- Regular: add a new node to the front of the list and

Count is updated.

Regular case:

Node *x;

x = new Node;

x->Next = Front;

Front = x;

Front->Elem = NewNum;

void llist::deleteFront(el_t& OldNum)

3 cases:

- Error case: if the List is empty, throw Underflow

- Special case: if currently only one Node,

give back the front node element through OldNum (pass by reference) and

make sure both Front and Rear become NULL. Count is updated.

- Regular: give back the front node element through OldNum (pass by reference)

and also removes the front node. Count is updated.

Regular case:

OldNum = Front->Elem;

Node *Second;

Second = Front->Next;

delete Front;

Front = Second;

void llist::deleteRear(el_t& OldNum)

3 cases:

- Error case: if empty, throw Underflow

- Special case: if currently only one node,

give back the rear node element through OldNum (pass by reference) and

make sure both Front and Rear become NULL. Count is updated.

- Regular: give back the rear node element through OldNum (pass by reference)

and also remove the rear node. Count is updated.

Regular case:

OldNum = Rear->Elem;

Node *p;

Make p go to the one right before rear (using while)

delete Rear;

Rear = p;

void llist::deleteIth(int I, el_t& OldNum)

4 cases:

- Error case:

If I is an illegal value (i.e. > Count or < 1) throw OutOfRange.

- Special cases: this should simply call deleteFront when I is 1 or

deleteRear when I is Count

- Regular: delete the Ith node (I starts out at 1). Count is updated.

and make sure you indicate the purposes of these local pointers>

void llist::addbeforeIth(int I, el_t newNum)

4 cases:

- Error case:

If I is an illegal value (i.e. > Count+1 or < 1) throw OutOfRange.

- Special cases: this should simply call addFront when I is 1 or addRear when

I is Count+1

- Regular: add right before the Ith node. Cout if updated.

and make sure you indicate the purposes of these local pointers>

================================================================================================================

LIST.H:

//----- Globally setting up the alias and struct ----------------

typedef int el_t ; // elements will be **

//a list node is defined here as a struct Node

// I could have done class Node and add the data members under public

// but it would use too much space

struct Node

{

el_t Elem; // elem is the element stored

Node *Next; // next is the pointer to the next node

};

//---------------------------------------------------------

class llist

{

private:

Node *Front; // pointer to the front node

Node *Rear; // pointer to the rear node

int Count; // counter for the number of nodes

public:

// Exception handling classes

class Underflow{};

class OutOfRange{}; // thrown when the specified Node is out of range

llist (); // constructor to create a list object

~llist(); // destructor to destroy all nodes

//**

bool isEmpty();

//**

void displayAll();

//**

void addFront(el_t);

//**

void addRear(el_t);

//**

void deleteFront(el_t&);

//**

void deleteRear(el_t&);

//**

void deleteIth(int, el_t&);

//**

void addbeforeIth(int, el_t);

};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago