1 Write a function called Insert that takes in four paramete

1. Write a function called Insert that takes in four parameters: an integer array, the size of the array, the new value to be inserted into the array, the index at which to insert the new value.This function should insert a a new value into the array, at the specified index. Note that this means that other values have to \"move\" to make room. The last value in the array will just disappear from the array. If the index is out of bounds for the array, abort the function with no change made to the array. This function does not return a value.

2. Write a function called Delete that takes in three parameters: an integer array, the size of the array, the index of the item to delete. This function should delete the value at the given index. The remaining items in the array will need to shift over to fill the \"empty\" slot. The last item in the array (now vacant) should be set to 0. If the given index is out of bounds for the array, abort the function without deleting anything.

3. Write a function called Reverse that takes in two parameters: an integer array, the size of the array.

4. Write a function called Sort that takes in two parameters: an integer array, the size of the array. This function should sort the array in ascending order. Note: You are NOT permitted to create any other Arrays to do this task (or any other task on this assignment). (See \"bubble sort\" in the book for help if needed, but you can use any type of sort you\'d like.). This function should not return a value.

5. Write a function called Found that takes in three parameters: an integer array, size of the array, The value to search for in the array.

This function should return true if the value was found in the array and false otherwise.

Solution

Here is the code for the specified functions for you:

#include <iostream>
using namespace std;

void Insert(int array[], int size, int newValue, int index)
{
for(int i = size - 2; i >= index; i--)
array[i+1] = array[i];
array[index] = newValue;
}
void Delete(int array[], int size, int index)
{
for(int i = index; i < size - 1; i++)
array[i] = array[i+1];
array[size-1] = 0;
}
void Reverse(int array[], int size)
{
for(int i = 0; i < size / 2 - 1; i++)
{
int temp = array[i];
array[i] = array[size - i - 1];
array[size-i-1] = temp;
}
}
void Sort(int array[], int size)
{
for(int i = 0; i < size; i++)
for(int j = 0; j < size-i-1; j++)
if(array[j] > array[j+1])
{
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
bool Found(int array[], int size, int value)
{
for(int i = 0; i < size; i++)
if(array[i] == value)
return true;
return false;
}

1. Write a function called Insert that takes in four parameters: an integer array, the size of the array, the new value to be inserted into the array, the index
1. Write a function called Insert that takes in four parameters: an integer array, the size of the array, the new value to be inserted into the array, the index

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site