请问如何通过myAdd 函数来实线数组元素的插入和排序,怎样将输入数组长度赋值给size。
#include <stdio.h>
#define MAX_SIZE 20
#define SUCCESS 0
int size; // global variable
int myAdd( int A[], int d )
{
}
int myBinarySearch_Iterative( int A[], int d )
{
}
int myRemove( int A[], int d )
{
}
int printArray( int A[])
{
int i;
printf("[ ");
for ( i = 0; i < size; i++ )
printf("%d ", A[ i ] );
printf( "]\n" );
return 0;
}
int main()
{
int myArray[MAX_SIZE];
int retCode, data, size;
char action;
char a[20];
do {
fgets(a, 20, stdin);
sscanf(a, "%c %d", &action, &data );
switch( action )
{
case 'a':
case 'A':
retCode = myAdd( myArray, data );
if ( retCode >= SUCCESS ) {
printArray( myArray);
}
else
printf( "Failed to add %d.\n", data );
break;
case 'r':
case 'R':
retCode = myRemove( myArray, data );
if ( retCode >= SUCCESS ) {
printArray( myArray);
}
else
printf( "Failed to remove %d.\n", data );
break;
case 's':
case 'S':
retCode = myBinarySearch_Iterative( myArray, data );
if( retCode >= 0 )
printf( "Found %d at index %d.\n", data, retCode );
else
printf( "Not found %d.\n", data );
break;
case 'q':
case 'Q':
break;
default:
printf( "Invalid operation %c\n", action );
}
} while ( action != 'q' && action != 'Q' );
return 0;
}