Create a data structure that is capable of storing a collect

Create a data structure that is capable of storing a collection of integers, and supporting the following operations:

- add(d, x): add the integer x to the collection for the data structure d
- remove(d): return and remove the last integer added to the data structure d (that is still in the collection)
- min(d): return the minimum value stored in the data structure d

All of the operations must run in O(1) time.

Clearly indicate what fields you are using in your data strucure, as well as how they are implemented (if there are multiple possible implementations).

Solution

#include \"ArrayList.h\";
#include <iostream>;
using namespace std;

ArrayList :: ArrayList()
{
int elements = 0;
int lastIndex=0;
int *arrayList= new int [elements];
}

void ArrayList :: add(int n, )
{

arrayList&[lastIndex]=n;

}

ArrayList* doubleSize(int [] arr&)
{
int [] arr2;= new ArrayList[arr->length*2];
for(int i=0; i<arr.length; i++)
arr2[i]=arr[i];
return arr2;
}

int ArrayList :: deleteLast()
{
int numDeleted=0;
if(arrayList!=0)
{
numDeleted=arrayList[size];
arrayList[size]=NULL;
if(size<
}
else
{
cout << \"Array is empty\";
}

return numDeleted;
}

int size()
{
int numElems=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]!=NULL)
numElems++;
}

return numElems;


}

int main()
{
cout << \"Test\" << endl;
}

/*******array list**************/

Create a data structure that is capable of storing a collection of integers, and supporting the following operations: - add(d, x): add the integer x to the coll
Create a data structure that is capable of storing a collection of integers, and supporting the following operations: - add(d, x): add the integer x to the coll

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site