Data structure Learning notes--sequential array 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.