the question is
using pointer variable:
a)write a program that receives a sorted array of integer.then it will read an integer value and insert that integer value in correct place
(using pointer variable)
-is it how im write the code right.
b)improve the first program code by allowing the program to just read an integer and insert it in its correct place.the program will continue to read until the user exit the program(must be menu driven)(p/s: i dont know how to improve this program..please help me )
for question (a)
-is it how im write the code right.i mean the pointer variable
#include<stdio.h>
int main()
{
const int arraySize = 5;
int data[arraySize] = {2,3,5,4,1};
int *insert;//temporary variable to hold element to insert
int a;
insert = &a;
//original array
printf("\nUnsorted Array = ");
for(int i=0;i < arraySize;i++)
printf("%3d", data[i]);
//insertion sort
//loop over the element of array
for( int next = 1;next < arraySize;next++)
{
a = data[ next ];//store the value in current element
int moveItem = next;//initialize location to place element
//search for the location to in which to put current element
while((moveItem > 0)&&(data[moveItem - 1] > a))
{
//shift element one slot to the right
data[moveItem]=data[moveItem - 1];
moveItem--;
}//end while
data[ moveItem ] = a;//place inserted element into the array
}//end for
//output sorted array
printf("\nSorted array = ");
for(i = 0;i< arraySize; i++)
printf("%3d",data[i]);
return 0;
}