Question: This problem deals with the Array and Linked List implementations of the Unsorted List ( AUList and LLUList ). Your solution must begin with the

This problem deals with the Array and Linked List implementations of the Unsorted List (AUList and LLUList). Your solution must begin with the base code available via Blackboard (AUList.h, AUList.cpp, LLUList.h, LLUList.cpp).

a. Create a function for the AUList structure AUList copyReverse() which creates a new AUList with identical elements, but in reverse order. Ex: if myList is an AUList with elements in the order 1, 4, 2, 8, 6, myList.copyReverse() will return an AUList with elements in the order 6, 8, 2, 4, 1.

(A).MAIN.CPP file

#include #include "AUList.h"

int main(int argc, char** argv) { AUList TestList; AUList* NewList; std::cout<<"Newly Created List: "; TestList.PrintList(); for (int i=0; i<10; i++) TestList.PutItem(100-i*10); std::cout<<"List after 'PutItem' calls: "; TestList.PrintList(); std::cout<<"Length after 'PutItem' calls: " < std::cout<<"IsFull after 'PutItem' calls? " < TestList.DeleteItem(50); std::cout<<"List after 'DeleteItem' call: "; TestList.PrintList(); std::cout<<"IsFull after 'DeleteItem' call? " < std::cout<<"Index of value 80: "< std::cout<<"Index of value 25: "< TestList.MakeEmpty(); std::cout<<"List after 'MakeEmpty': "; TestList.PrintList(); return 0; }

-----------------------------------------------AUList.cpp

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

AUList::AUList() { length = 0; //a newly constructed list has 0 elements; we don't care about the contents of the array. } bool AUList::IsFull() const { return (length == MAXSIZE); //Remember that preprocessor commands like #define carry over into files to which they are included (like this one!) } int AUList::GetLength() const { return length; }

int AUList::GetItem(int gitem) { int searchiter; for (searchiter = length-1; searchiter>=0; searchiter--) { //main loop decrements from the final index in the list down to -1 if (ListItems[searchiter] == gitem) //if this condition is met, we have a match break; //break terminates the innermost-loop in progress (so in this case, the for-loop. Has no impact on other conditionals or scope. } return searchiter; } void AUList::MakeEmpty() { length = 0; //as with the constructor, we need do nothing to the actual array, as it now "junk" data } void AUList::PutItem(int item) { //This function assumes the "IsFull" condition hasn't been met. ListItems[length] = item; //Remember that C++ uses 0-indexing. length++; } void AUList::DeleteItem(int item) { //This is the less efficient version of what we discussed ("Move-Up") that maintains list order //Note: assumes item is actually in list

bool indexfound=false; for (int loc=0; loc if (ListItems[loc]==item) indexfound=true; if (indexfound) ListItems[loc]=ListItems[loc+1]; } length--; }

void AUList::ResetList() { currentPos = -1; //We want the position BEFORE the first element, since incrementation in GetNextItems happens first }

int AUList::GetNextItem() { currentPos++; //Remember that currentPos is a class member variable return ListItems[currentPos]; }

void AUList::PrintList() { //simple function to print a list's items in stored order std::cout<<"("; for (int loc=0; loc std::cout< if (loc std::cout<<", "; } std::cout<<")"< }

---------------------------------------AUList.h

#define MAXSIZE 10

//Remember that header files should contain DECLARATIONS, but not DEFINITIONS for the associated class functions. class AUList { public: AUList(); // Constructor void MakeEmpty(); // Returns the list to the empty state. bool IsFull() const; //Determines whether list is full. (Precondition -- list has been initialized). Return value of "True" indicates class is full. int GetLength() const; //Determines the number of elements in list.

int GetItem(int); //Retrieves position of list element matching input item (if present). If not present, -1 is returned.

void PutItem(int); //Adds the item to the list. void DeleteItem(int); //Deletes the element whose key matches item's key. void ResetList(); //Initializes iterator's current position for an iteration through the list. void PrintList(); //Print all elements of the list in a readable format. int GetNextItem(); //Gets the next element in the list.

private: int length; int ListItems[MAXSIZE]; int currentPos; };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!