SlideShare a Scribd company logo
1 of 3
Download to read offline
Implement the ListArray ADT-
*Implement the following operations:
- constructor, assignment operator, destructor
-insert, remove, replace, clear
-isFull, isEmpty
-gotoBeginning, gotoEnd, gotoNext, gotoPrior, getCursor
#ifndef LISTARRAY_H
#define LISTARRAY_H
#include
#include
using namespace std;
#pragma warning( disable : 4290 )
template < typename DataType >
class List
{
public:
static const int MAX_LIST_SIZE = 10; // Default maximum list size
// Constructors
List ( int maxNumber = MAX_LIST_SIZE ); // Default constructor
List ( const List& source ); // Copy constructor
// Overloaded assignment operator
List& operator= ( const List& source );
// Destructor
virtual ~List ();
// List manipulation operations
virtual void insert ( const DataType& newDataItem ) // Insert after cursor
throw ( logic_error );
void remove () throw ( logic_error ); // Remove data item
virtual void replace ( const DataType& newDataItem ) // Replace data item
throw ( logic_error );
void clear (); // Clear list
// List status operations
bool isEmpty () const; // List is empty
bool isFull () const; // List is full
// List iteration operations
void gotoBeginning () // Go to beginning
throw ( logic_error );
void gotoEnd () // Go to end
throw ( logic_error );
bool gotoNext () // Go to next data item
throw ( logic_error );
bool gotoPrior () // Go to prior data item
throw ( logic_error );
DataType getCursor () const
throw ( logic_error ); // Return data item
// Output the list structure -- used in testing/debugging
virtual void showStructure () const;
// In-lab operations
void moveToNth ( int n ) // Move data item to pos. n
throw ( logic_error );
bool find ( const DataType& searchDataItem ) // Find data item
throw ( logic_error );
protected:
// Data members
int maxSize,
size, // Actual number of data item in the list
cursor; // Cursor array index
DataType *dataItems; // Array containing the list data item
};
#endif
Solution
#include "ListArray.h" Struct List List ::List(int maxNumber = MAX_LIST_SIZE) {
size = cursor = 0; maxSize = maxNumber; dataItems = new DataType
[maxNumber]; for(int i = 0; i < maxNumber; i++) dataItems[i] = NULL; }
List ::List(const List& source) { maxSize = MAX_LIST_SIZE;
dataItems = new DataType [MAX_LIST_SIZE]; for(int i = 0; i < MAX_LIST_SIZE;
i++) dataItems[i] = source.dataItems[i]; size = source.size; cursor =
source.cursor; } List ::operator= (const List &source) { this -> clear();
for(int i = 0; i < maxSize; i++) dataItems[i] = source.dataItems[i]; //return
source; } List::~List() { delete [] dataItems; } void List_insert(const
DataType &newDataItem) { if(size == 0) dataItems[cursor] = newDataItem;
else { dataItems[cursor + 1] = newDataItem; } size++;
cursor = size - 1; } void List_remove() { dataItems[cursor] = NULL; size--
; if(dataItems[cursor + 1] == NULL) cursor = 0; else
cursor++; } void List_replace(const DataType &newDataItem) { dataItems[cursor]
= newDataItem; } void List_clear() { for(int i = 0; i < size; i++)
dataItems[i] = NULL; size = cursor = 0; } bool List_isEmpty() const {
return (size == 0); } bool List_isFull() const { return (size == maxSize); } void
List_gotoBeginning() { cursor = 0; } void List_gotoEnd() { cursor = size - 1;
} bool List_gotoNext() { if(dataItems[cursor + 1] != NULL) {
cursor++; return true; } else return false; } bool
List_gotoPrior() { if(cursor != 0) { cursor--; return true;
} else return false; } DataType List_getCursor() const { return
dataItems[cursor]; } void List_showStructure() const { cout << "Size: " << size
<< " Cursor: " << cursor << endl; cout << "List: "; for(int i = 0; i < maxSize;
i++) { cout << dataItems[i]; if(i != maxSize - 1)
cout << ", "; } cout << endl; }

More Related Content

Similar to Implement the ListArray ADT-Implement the following operations.pdf

My question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfMy question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfjeetumordhani
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Pleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfPleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfvinodagrawal6699
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Change the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdfChange the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdffatoryoutlets
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfPleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfvinodagrawal6699
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfFOREVERPRODUCTCHD
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfmallik3000
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdfangelsfashion1
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfarishmarketing21
 

Similar to Implement the ListArray ADT-Implement the following operations.pdf (20)

Adt of lists
Adt of listsAdt of lists
Adt of lists
 
My question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfMy question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdf
 
강의자료6
강의자료6강의자료6
강의자료6
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Pleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfPleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdf
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
강의자료7
강의자료7강의자료7
강의자료7
 
강의자료10
강의자료10강의자료10
강의자료10
 
Change the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdfChange the driver file (the main .cpp) so that it asks the user to e.pdf
Change the driver file (the main .cpp) so that it asks the user to e.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
week-20x
week-20xweek-20x
week-20x
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfPleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
Arrays
ArraysArrays
Arrays
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 

More from petercoiffeur18

John, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfJohn, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfpetercoiffeur18
 
In what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfIn what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfpetercoiffeur18
 
i need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfi need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfpetercoiffeur18
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfpetercoiffeur18
 
how internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfhow internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfpetercoiffeur18
 
For an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfFor an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfpetercoiffeur18
 
Exercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfExercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfpetercoiffeur18
 
Discuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfDiscuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfpetercoiffeur18
 
C++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfC++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfpetercoiffeur18
 
any idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfany idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfpetercoiffeur18
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfpetercoiffeur18
 
A radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfA radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfpetercoiffeur18
 
21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdfpetercoiffeur18
 
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfCase 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfpetercoiffeur18
 
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfx , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfpetercoiffeur18
 
Why would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfWhy would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfpetercoiffeur18
 
When discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfWhen discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfpetercoiffeur18
 
What relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfWhat relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfpetercoiffeur18
 
what is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfwhat is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfpetercoiffeur18
 
What are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfWhat are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfpetercoiffeur18
 

More from petercoiffeur18 (20)

John, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfJohn, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdf
 
In what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfIn what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdf
 
i need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfi need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdf
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
 
how internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfhow internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdf
 
For an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfFor an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdf
 
Exercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfExercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdf
 
Discuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfDiscuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdf
 
C++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfC++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdf
 
any idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfany idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdf
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
 
A radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfA radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdf
 
21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf
 
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfCase 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
 
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfx , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
 
Why would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfWhy would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdf
 
When discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfWhen discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdf
 
What relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfWhat relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdf
 
what is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfwhat is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdf
 
What are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfWhat are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdf
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 

Implement the ListArray ADT-Implement the following operations.pdf

  • 1. Implement the ListArray ADT- *Implement the following operations: - constructor, assignment operator, destructor -insert, remove, replace, clear -isFull, isEmpty -gotoBeginning, gotoEnd, gotoNext, gotoPrior, getCursor #ifndef LISTARRAY_H #define LISTARRAY_H #include #include using namespace std; #pragma warning( disable : 4290 ) template < typename DataType > class List { public: static const int MAX_LIST_SIZE = 10; // Default maximum list size // Constructors List ( int maxNumber = MAX_LIST_SIZE ); // Default constructor List ( const List& source ); // Copy constructor // Overloaded assignment operator List& operator= ( const List& source ); // Destructor virtual ~List (); // List manipulation operations virtual void insert ( const DataType& newDataItem ) // Insert after cursor throw ( logic_error ); void remove () throw ( logic_error ); // Remove data item virtual void replace ( const DataType& newDataItem ) // Replace data item throw ( logic_error ); void clear (); // Clear list // List status operations bool isEmpty () const; // List is empty bool isFull () const; // List is full
  • 2. // List iteration operations void gotoBeginning () // Go to beginning throw ( logic_error ); void gotoEnd () // Go to end throw ( logic_error ); bool gotoNext () // Go to next data item throw ( logic_error ); bool gotoPrior () // Go to prior data item throw ( logic_error ); DataType getCursor () const throw ( logic_error ); // Return data item // Output the list structure -- used in testing/debugging virtual void showStructure () const; // In-lab operations void moveToNth ( int n ) // Move data item to pos. n throw ( logic_error ); bool find ( const DataType& searchDataItem ) // Find data item throw ( logic_error ); protected: // Data members int maxSize, size, // Actual number of data item in the list cursor; // Cursor array index DataType *dataItems; // Array containing the list data item }; #endif Solution #include "ListArray.h" Struct List List ::List(int maxNumber = MAX_LIST_SIZE) { size = cursor = 0; maxSize = maxNumber; dataItems = new DataType [maxNumber]; for(int i = 0; i < maxNumber; i++) dataItems[i] = NULL; } List ::List(const List& source) { maxSize = MAX_LIST_SIZE; dataItems = new DataType [MAX_LIST_SIZE]; for(int i = 0; i < MAX_LIST_SIZE; i++) dataItems[i] = source.dataItems[i]; size = source.size; cursor = source.cursor; } List ::operator= (const List &source) { this -> clear(); for(int i = 0; i < maxSize; i++) dataItems[i] = source.dataItems[i]; //return
  • 3. source; } List::~List() { delete [] dataItems; } void List_insert(const DataType &newDataItem) { if(size == 0) dataItems[cursor] = newDataItem; else { dataItems[cursor + 1] = newDataItem; } size++; cursor = size - 1; } void List_remove() { dataItems[cursor] = NULL; size-- ; if(dataItems[cursor + 1] == NULL) cursor = 0; else cursor++; } void List_replace(const DataType &newDataItem) { dataItems[cursor] = newDataItem; } void List_clear() { for(int i = 0; i < size; i++) dataItems[i] = NULL; size = cursor = 0; } bool List_isEmpty() const { return (size == 0); } bool List_isFull() const { return (size == maxSize); } void List_gotoBeginning() { cursor = 0; } void List_gotoEnd() { cursor = size - 1; } bool List_gotoNext() { if(dataItems[cursor + 1] != NULL) { cursor++; return true; } else return false; } bool List_gotoPrior() { if(cursor != 0) { cursor--; return true; } else return false; } DataType List_getCursor() const { return dataItems[cursor]; } void List_showStructure() const { cout << "Size: " << size << " Cursor: " << cursor << endl; cout << "List: "; for(int i = 0; i < maxSize; i++) { cout << dataItems[i]; if(i != maxSize - 1) cout << ", "; } cout << endl; }