Question: I have all the code I just need help with a loop and if statement. After this printList function, I need to to make and

I have all the code I just need help with a loop and if statement.

After this printList function, I need to to make and if statement/loop that deletes the 3 remaining numbers in order (lowest to high) so it would first do the Delete function to -90 then 15, then 64.

********************************************

printList(data, length);

Delete(data, 64, length);

Delete(data, 15, length);

Delete(data, -90, length);

*********************************************

#include

using namespace std;

void Insert(int data[], int item, int& length)

{

data[length] = item;

length++;

}

bool isEmpty(int data[], int length)

{

return length == 0;

}

bool isPresent(int data[], int item, int length)

{

for (int i = 0; i < length; i++)

{

if (data[i] == item)

return true;

}

return false;

}

void Delete(int data[], int item, int& length)

{

int index = -1;

for (int i = 0; i < length; i++)

{

if (data[i] == item)

{

index = i;

break;

}

}

if (index != -1)

{

for (int i = index; i < length - 1; i++)

{

data[i] = data[i + 1];

}

length--;

}

}

void printList(int data[], int length)

{

for (int i = 0; i < length; i++)

{

cout << data[i] << " ";

}

cout << endl;

}

int main()

{

int data[10];

int length = 0;

Insert(data, 15, length);

Insert(data, 39, length);

Insert(data, -90, length);

Insert(data, 64, length);

cout << "The current length of the list is: " << length << endl;

if (isPresent(data, 39, length))

{

cout << "39 is in the list." << endl;

Delete(data, 39, length);

}

else

{

cout << "39 is not in the list." << endl;

}

printList(data, length);

Delete(data, 64, length);

Delete(data, 15, length);

Delete(data, -90, length);

if (isEmpty(data, length))

{

cout << "The list is empty." << endl;

}

else

{

cout << "The list is not empty." << endl;

}

return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!