C++ (n each of the operations, in comment form it states what each operation is
ID: 3787420 • Letter: C
Question
C++ (n each of the operations, in comment form it states what each operation is looking for and some of the implementations has already been started. Need help with finishing the rest of the implementation for each of the following operations below. Thank you.)
Implement the ListArray ADT [the declaration is given in ListArray.h, posted below]
Implement the following operations:
constructor, assignment operator, destructor
insert, remove, replace, clear
isFull, isEmpty
toBeginning, gotoEnd, gotoNext, gotoPrior, getCursor
-----------------------------------------------------------------------------------------------------
#include "ListArray.h"
template < typename DataType >
List::List ( int maxNumber )
{
//needs implementation
}
template < typename DataType >
List::List ( const List& source )
{
//needs implementation
}
template < typename DataType >
List& List::operator= ( const List& source )
{
return *this;
}
template < typename DataType >
List::~List ()
{
}
template < typename DataType >
void List::insert ( const DataType& newDataItem )
throw ( logic_error )
{
/*
Inserts newDataItem after the cursor.
if ( size >= maxSize )
throw logic_error("list is full ");
for ( int j = size ; j > cursor+1 ; j-- )
dataItems[j] = dataItems[j-1];
Update size;
Update dataItems;
Update cursor;
*/
}
template < typename DataType >
void List::remove () throw ( logic_error )
{
/*
Check if the list is empty...;
for ( j = cursor ; j < size-1 ; j++ )
dataItems[j] = dataItems[j+1];
Update size;
Set the cursor
*/
}
template < typename DataType >
void List::replace ( const DataType& newDataItem )
throw ( logic_error )
{
// Replaces the item marked by the cursor with newDataItem
}
template < typename DataType >
void List::clear ()
{
}
template < typename DataType >
bool List::isEmpty () const
{
return false;
}
template < typename DataType >
bool List::isFull () const
{
/*
Returns true if a list is full. Otherwise, returns 0.
return ( size == maxSize );
*/
}
template < typename DataType >
void List::gotoBeginning ()
throw ( logic_error )
{
/*
Moves the cursor to the beginning of the list.
Check if list is empty,...
cursor = 0;
*/
}
template < typename DataType >
void List::gotoEnd ()
throw ( logic_error )
{
}
template < typename DataType >
bool List::gotoNext ()
throw ( logic_error )
{
/*
If the cursor is not at the end of a list, then moves the
cursor to the next item in the list and returns true.
Check if list is empty
if ( cursor != size-1 )
{
Increase cursor;
...
}
else
...
*/
}
template < typename DataType >
bool List::gotoPrior ()
throw ( logic_error )
{
return false;
}
template < typename DataType >
DataType List::getCursor () const
throw ( logic_error )
{
/*
Returns the item marked by the cursor.
Requires that the list is not empty.
return dataItems[cursor];
*/
}
#include "show3.cpp"
template < typename DataType >
void List::moveToNth ( int n )
throw ( logic_error )
{
}
template < typename DataType >
bool List::find ( const DataType& searchDataItem )
throw ( logic_error )
{
/*
Begins the search from the cursor position.
Moves the cursor through the list until either searchDataItem
is found or the end of the list is reached.
while ( cursor < size && dataItems[cursor] !=searchDataItem )
Move forward;
if ( searchDataItem is found)
return true;
else
...
*/
}
template < typename DataType >
void List::gotoEnd ()
throw ( logic_error )
{
}
template < typename DataType >
bool List::gotoNext ()
throw ( logic_error )
{
return false;
}
template < typename DataType >
bool List::gotoPrior ()
throw ( logic_error )
{
return false;
}
template < typename DataType >
DataType List::getCursor () const
throw ( logic_error )
{
DataType t;
return t;
}
#include "show3.cpp"
template < typename DataType >
void List::moveToNth ( int n )
throw ( logic_error )
{
}
template < typename DataType >
bool List::find ( const DataType& searchDataItem )
throw ( logic_error )
{
return false;
}