array.c
//inserts element to index param i in array at param ap
//if param i < 0, wrap once around array in reverse (i = length - i)
//inits array if necessary
//returns 1 if success, 0 if fails (out of bounds)
inserts element to index param i in array at param ap
if param i < 0, wrap once around array in reverse (i = length - i)
inits array if necessary
returns 1 if success, 0 if fails (out of bounds)
inserts element to index param i in array at param ap if param i < 0 wrap once around array in reverse ( i = length - i ) inits array if necessary returns 1 if success 0 if fails ( out of bounds )
int array_insert(array_t* ap, int i, int x) {	
	if( !ap->array ) {
		init_array(ap, 10);
	}
	if( i < 0 ) {
		i = ap->length + i;
	}
	if( i < 0 ) {
		WARN("index out of bounds for array insert");
		EXIT();
		return(0);
	}
	if( ap->length == ap->capacity ) {
		int e = array_resize(ap, ap->capacity * 2);
		WARN_EXIT_IF(!e, "array resize for insert failed");
		if( !e ) { return(0); }
	}
	int j;
	for(j=ap->length; j>i; j--) {
		ap->array[j] = ap->array[j-1];
	}
	ap->array[i] = x;
	ap->length++;
	return(1);
}
int array_insert ( array_t * ap , int i , int x ) { if ( ! ap -> array ) { init_array ( ap , 10 ) ; } if ( i < 0 ) { i = ap -> length + i ; } if ( i < 0 ) { WARN ( " " ) ; EXIT ( ) ; return ( 0 ) ; } if ( ap -> length == ap -> capacity ) { int e = array_resize ( ap , ap -> capacity * 2 ) ; WARN_EXIT_IF ( ! e , " " ) ; if ( ! e ) { return ( 0 ) ; } } int j ; for ( j = ap -> length ; j > i ; j -- ) { ap -> array [ j ] = ap -> array [ j - 1 ] ; } ap -> array [ i ] = x ; ap -> length ++ ; return ( 1 ) ; }
inserts element to index param i in array at param ap
if param i < 0, wrap once around array in reverse (i = length - i)
inits array if necessary
returns 1 if success, 0 if fails (out of bounds)
inserts element to index param i in array at param ap if param i < 0 wrap once around array in reverse ( i = length - i ) inits array if necessary returns 1 if success 0 if fails ( out of bounds )