Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I NEED HELP WITH MY SYNTAX Create the function from part a. but for the LLUList structure (it should return a LLUList with elements in

I NEED HELP WITH MY SYNTAX

Create the function from part a. but for the LLUList structure (it should return a LLUList with elements in reverse order.

// Implementation file for AUList #include #include "LLUList.h"

struct LNode { int item; LNode* next; };

LLUList::LLUList() { ListStart=NULL; }

LLUList::~LLUList() { LNode* tempPtr; while (ListStart != NULL) { tempPtr = ListStart; ListStart = ListStart->next; delete tempPtr; } }

bool LLUList::IsFull() const { LNode* testNode; try { testNode = new LNode; delete testNode; return false; } catch(std::bad_alloc exception) { return true; } }

int LLUList::GetLength() const { LNode* LenPos = ListStart; int length=0; while (LenPos != NULL) { LenPos=LenPos->next; length++; } return length; };

int LLUList::GetItem(int gitem) { //Procedure is similar to that of AUList, although the relevant data is stored different. //also, it's better for LLUList to proceed in order from the beginning int position=0; LNode* nodeIter; nodeIter=ListStart; while ((nodeIter != NULL) && (nodeIter->item !=gitem)) { nodeIter=nodeIter->next; position++; } if (nodeIter==NULL) return -1; else return position; }

void LLUList::MakeEmpty() { //Unlike the AUList implementation, we need to step through and delete EVERY node LNode* tempPtr; while (ListStart != NULL) { tempPtr = ListStart; ListStart = ListStart->next; delete tempPtr; } }

void LLUList::PutItem(int newitem) { LNode* newNode; //Get a pointer newNode = new LNode; //Create a new node. newNode->item = newitem; // Store the item in the node newNode->next = ListStart; // Store address of next node ListStart = newNode; // Redirect start of list }

void LLUList::DeleteItem(int ditem) { //A little bit tricky because we need to "scout ahead" and relink the object //before the deleted object to the one after. LNode *tmpNode, *nodeIter; if (ListStart->item == ditem) { tmpNode=ListStart; ListStart=ListStart->next; } else{ nodeIter=ListStart; while ((nodeIter->next->item !=ditem)) nodeIter=nodeIter->next; tmpNode=nodeIter->next; nodeIter->next=(nodeIter->next)->next; } delete(tmpNode); }

void LLUList::ResetList() { curPos=ListStart; }

int LLUList::GetNextItem() { int myitem; if (curPos == NULL) //The implemented option throw an errors if someone tries to access an item past the last one. throw(38); //EOS Exception myitem = curPos->item; curPos=curPos->next; return myitem; };

void LLUList::PrintList() { LNode* printPtr; printPtr=ListStart; std::cout<<"("; while (printPtr != NULL) { std::cout<item; if (printPtr->next!=NULL) std::cout<<", "; printPtr=printPtr->next; } std::cout<<")"<

LLUList myReverseCopy = mycopy.Copyreverse(); { LLUList reverse; for (int loc = length - 1; loc >= 0; loc--) { reverse::PutItem(Liststart[loc]); } return reverse; }

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_2

Step: 3

blur-text-image_3

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students explore these related Databases questions