# include<stdio.h># include<malloc.h># include<stdlib.h>structarr{int*pbase;//The address of the first element of the array is stored intLen//The maximum number of elements the array can hold intCnt//the number of valid elements in the current array};voidInit_arr (structARR *parr,intlength);BOOLAppend_arr (structARR *parr,intvalue);BOOLInsert_arr (structARR *parr,intPosintvalue);BOOLDelete_arr (structARR *parr,intPosint*pVal);BOOLIs_empty (structARR *PARR);BOOLIs_full (structARR *PARR);voidSort_arr (structARR *PARR);voidShow_arr (structARR *PARR);voidInversion_arr (structARR *PARR);intMainvoid){ structarr arr; intVal; Arr.len=5; Init_arr (&Arr,arr.len); Show_arr (&arr); Append_arr (&arr,1); Show_arr (&arr); Delete_arr (&arr,1,&val); return 0;}voidInit_arr (structARR *parr,intlength) {PARR->pbase= (int*)malloc(sizeof(int)*length); if(parr->pbase=NULL) {printf ("dynamic memory allocation failure"); Exit (-1); } Else{PARR->len=length; PARR->cnt=0; } return;}BOOLIs_empty (structARR *PARR) { if(parr->cnt==0) return true; Else return false;}BOOLIs_full (structARR *PARR) { if((parr->cnt) = = (parr->len)) return true; Else return false;}voidShow_arr (structARR *PARR) { inti; if(Is_empty (PARR))//why not &parr, because PARR is the address itself?{printf ("array is empty \ n"); } Else { for(i=0; i<parr->cnt;i++) {printf ("%d",parr->Pbase[i]); } } }BOOLAppend_arr (structARR *parr,intvalue) { if(Is_full (PARR)) {return false; } Else{PARR->pbase[parr->cnt]=value; (PArr->CNT) + +; return true; }}BOOLInsert_arr (structARR *parr,intPosintvalue) { inti; if(Is_full (PARR))return false; if(pos<1|| pos>parr->cnt+1) return false; for(i=parr->cnt-1; i>=pos-1; i--) {PARR->pbase[i+1]=parr->Pbase[i]; } PARR->pbase[pos-1]=value; (PArr->CNT) + +; return true;}BOOLDelete_arr (structARR *parr,intPosint*pVal) { inti; if(Is_empty (PARR))return false; if(pos<1|| Pos>parr->CNT)return false; *pval=parr->pbase[pos-1]; for(i=pos;i<parr->cnt;i++) {PARR->pbase[i-1]=parr->Pbase[i]; } (PARR->CNT)--;}voidInversion_arr (structARR *PARR) { inti; intj=parr->cnt-1; intT; while(i<j) {T=parr->Pbase[i]; PARR->pbase[i]=parr->Pbase[j]; PARR->pbase[j]=T; ++i; --J; } return;}voidSort_arr (structARR *PARR) { inti,j,t; for(i=0; i<parr->cnt;i++) { for(j=i+1; j<parr->cnt;j++) { if(parr->pbase[i]>parr->Pbase[j]) {T=parr->Pbase[i]; PARR->pbase[i]=parr->Pbase[j]; PARR->pbase[j]=T; } } }}
Data structure (array manipulation) C language implementation