#include <iostream>
usingnamespace std;
// You need to define the functions remove (int value), moveTowardEnd (int index), moveTowardFront (int index), ~Array(), and print ().
// Class definition
class Array
{
private:
int* arr;
int capacity;
int size;
void moveTowardFront(int index);
void moveTowardEnd(int index);
public:
Array(int capacity);
~Array();
void insert(int value);
void remove(int value);
void print() const;
};
// Constructor
Array::Array(int cap)
:capacity(cap)
{
arr = newint[capacity];
size = 0;
}
// Destructor
Array :: ~Array()
{
//YOUR CODE
}
// Insert member function
void Array::insert(int value)
{
if (size == 0)
{
arr[0] = value;
size++;
return;
}
int index = 0;
while (value > arr[index] && index < size)
{
index++;
}
moveTowardEnd(index);
arr[index] = value;
size++;
}
// Delete member function
void Array::remove(int value)
{
int index = 0;
while (value != arr[index] && index < size)
{
index++;
}
if (index == size)
{
cout << value << " is not in the list. ";
cout << "No removal." << endl;
return;
}
moveTowardFront(index++);
size--;
}
// Print member function
void Array::print() const
{
//YOUR CODE
}
// Helper function to move the elements of array towards end
void Array::moveTowardEnd(int index)
{
//YOUR CODE
}
// Helper function to move the elements of array towards front
void Array::moveTowardFront(int index)
{
//YOUR CODE
}
int main()
{
// Declaration of any array of capacity 20
Array array(20);
// Inserting some elements and printing array
array.insert(15);
array.insert(13);
array.insert(10);
array.insert(14);
array.insert(11);
array.insert(17);
array.insert(14);
cout << "Printing array after insertions: " << endl;
array.print();
cout << endl;
// Removing two elements and printing array
array.remove(13);
array.remove(11);
cout << "Printing array after removals: " << endl;
array.print();
cout << endl;
// Inserting two more elements and printing array
array.insert(8);
array.insert(22);
cout << "Printing array after more insertion" << endl;
array.print();
cout << endl;
// Try to remove an element, which is not in the array
array.remove(31);
return 0;
}
moveTowardEnd( index )
{
/*
s = size
WHILE s > index :
arr[s+1] = arr[s]
s = s - 1
*/
}
moveTowardFront( index )
{
// Similar moveTowardEnd()
}
print()
{
/*
FOREACH number IN arr:
std::cout << number << '\n';
*/
}
~Array()
{
// deallocate arr
}