Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a data structure that is capable of storing a collection of integers, and

ID: 3921632 • Letter: C

Question

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).

Explanation / Answer

#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**************/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote