#include <stdio.h> #include <stdlib.h> #include < String .h> struct the Array // define a data storage structure { int * Data; // memory address int length; // cis number table length int listsize ; // order table size }; typedef struct the Array the Array; the Array * createArray () { the Array * TEMP = (the Array *) the malloc ( the sizeof (the Array)); // order table initializing structure IF (TEMP == NULL) // determine whether the application is successful memory { the printf ( " order table initialization failure \ n-! " ); return NULL; } TEMP -> Data = ( int *) the malloc ( the sizeof ( int ) * 10 ); // Application 10 int size memory temp-> length = 0 ; TEMP -> listsize = 10 ; the printf ( " sequence table created \ n-! " ); return TEMP; } int insertArray (ARR the Array *, int I, int n-) // store data to sequential table { IF (I < . 1 || I> arr-> length + . 1 ) // determines whether the position of the insertion method, only the insertion order, return 0 ; IF (arr-> length> = arr-> listsize) // Dynamic allocate memory space if more memory is full the application, with the expansion in the original size realloc { ARR -> Data = ( int *) realloc (arr-> Data, (arr-> listsize + . 5 ) * the sizeof ( int ) ); IF (arr-> Data == NULL) return NULL; ARR -> + = listsize . 5 ; } int K; for (K = arr-> length - . 1; K> = I - . 1 ; K-- ) { ARR -> Data [K + . 1 ] = arr-> Data [K]; } ARR -> Data [I- . 1 ] = n-; ARR -> length ++ ; return . 1 ; } void Show_Array (ARR the Array *) // print order of elements in the table { IF (arr-> length == 0 ) { the printf ( " order table is empty \ n-! " ); } the else { the printf ( " sequence table of elements:" ); For ( int I = 0 ; I <arr-> length; I ++ ) { the printf ( " % D " , arr-> Data [I]); } the printf ( " \ n- " ); } } void Find_Ch_Array ( * ARR the Array, int n) // lookup table in order of the n-th element value position { IF (arr-> Data == NULL) the printf ( " order table is empty \ n! " ); IF (arr-> length < the n-) printf (" Does not keep so much data \ n-! " ); The else the printf ( " value of% d elements:% d \ n- ' , n-, arr-> Data [n-- . 1 ]); } void Set_Ch_Array (the Array ARR *, int n-, int X) { IF (arr-> Data == NULL) the printf ( " order table is empty \ n-! " ); IF (arr-> length < n-) the printf ( " not exist so much ! data \ n- " ); the else ARR -> data [n-- . 1 ] = X; the printf ( "Replace success \ the n-! " ); }
void list_insert_arr (Array * arr, int n) // insert data specified position
{
IF (arr-> NULL Data ==)
the printf ( "order table is empty \ n-!");
IF (arr-> length <n-)
the printf ( "not exist so much data \ n-!");
the else
{
for (int I = 0; I <10; I ++)
{
int nun;
Scanf ( "% D", & nun);
insertArray (ARR, n-+ I , nun);
}
}
}
int main() { Array* a=createArray(); for (int i = 0; i < 50; i++) { insertArray(a, i, i + 10); } Show_Array(a); Find_Ch_Array(a, 5); system("pause"); return 0; }