Then yesterday's array operation, the array is initialized, we want to add elements inside, you can append or insert at the end, the first array is empty, so append
intAppendlist (sqlist*PArr, Elemtype val) { if(Is_full (PARR))//determine if the array is full{printf ("The array is full! \ n"); return 0; } PARR->elem[parr->listsize] = val;//assign the appropriate data to the arrayparr->listsize++;//The current array of available elements plus one return 1;}intIs_full (sqlist*PARR) { if(Parr->listsize = = parr->length)return 1; Else return 0;}
We can write it into the program to verify, then insert the element
intInsertlist (sqlist* PARR,intPos, Elemtype val) { if(Is_full (PARR)) {printf ("The array is full! \ n"); return 0; } if(pos<0|| Pos> (parr->listsize+1) {printf ("Insert range Error or array out of bounds! \ n"); return 0; } for(inti = parr->listsize-1; I >= pos-1; i--)//move an array element one at a backwardParr->elem[i +1] = parr->Elem[i]; PARR->elem[pos-1] = val;//inserting values into a locationparr->listsize++; return 1;}
The algorithm for deleting elements is basically similar, that is, you have to define a variable to accept the deleted value, the order table is similar, then write a small program to use this!
Data structure Learning notes--sequential array 2