In: Computer Science
Write, specify and prove the function reverse that
reverses an array in place. Take care
of the unmodified part of the array at some iteration of the loop.
Assume that the swap
function is already proved. Note: Prototype is as below. [7 M]
[CO2]
void swap(int* a, int* b);
void reverse(int* array, size_t len){
}
#include <stdio.h>
void swap(int *a, int *b)
{
if (a != b)
{
*a += *b;
*b = *a - *b;
*a -= *b;
}
}
void reverse(int *array, size_t len)
{
size_t i = len - 1;
size_t j = 0;
while (i > j)
{
swap(array[i],array[j]);
i--;
j++;
}
}
******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION
******************************************************************************************