Explain in your own words the Analysis of each Array list operation (add, remove and find)?
Consider a Dynamic Array declared inside the code using int* z = new int[10]; . How we will free the memory after we are done with the z array?
Consider a Dynamic Array declared inside the code using int* z = new int[10]; . How we will free the memory after we are done with the z array?
Explain in your own words the Analysis of each Array list operation (add, remove and find)?
Q: Explain the given code in your own words.
find(X): traverse the array until X is located.
int find(int X)
{
int j;
for(j=1; j < size+1; j++ )
if( A[j] == X ) break;
if( j < size+1 ) { // found X
current = j; // current points to where X found
return 1; // 1 for true
}
return 0; // 0 (false) indicates not foundFor the given code you task is to to implement the following:
1)destructor LList::~LList ()
struct Node {
int data;
Node *next;
class LList {
public:
LList(); ~LList();
private:
Node *head;
int size;
};
LList::LList ()
{
head = NULL;
size = 0; }
class List
{
public:
int item;
int pos=0;
List* nextNode;
};
void Insert_Element(List** head, char data)
{
List* node = new List();
node->item = data;
node->nextNode = (*head);
(*head) = node;
}
void PrinList(List *node){
List *temp = node;
while(temp !=NULL){
cout<<temp->item<<" ";
node->pos ++;
temp = temp->nextNode;
}
cout<<"\n";
}
int Length(List *node){
return node->pos;
}
bool is_Empty(List *node){
if(node->pos==0){
return true;
}
else {
return false;
}
}
void Copy_List(List*node, List *list){
List * temp = node;
while(temp !=NULL){
int data = temp->item;
Insert_Element(&list, data);
temp = temp->nextNode;
}
cout<<"The copied list is:\n";
PrinList(list);
}
note:
Create constructor(default,parameterized and copy) and a manu of test the functions.
Prepare a c++ program
board[4][3] = { {2,3,1},{15,25,13},{20,4,7},{11,18,14}};
Prepare a c++ program of the two-dimensional array of the sample run below:
Sample Run:
[0] [1] [2] [3] [4] [5]
[0]
[1]
[2]
[3]
[4]
[5] 9.5
[6]
[7]
[8]
[9]
[10]
[11]