Basic operation of data structure 2

Source: Internet
Author: User


1 //Lookup of sequential tables2 //Find by Value3 //find the same data element location as E in L4 intLocateelem (sqlist l,elemtype e) {5 for(i=0; i<l.length;i++)6 if(l.elem[i]==e)returni+1;7 return 0;8 }9 //average lookup length for sequential lookupsTen //ASL One A //implementation of the insertion algorithm -Status listinsert_sq (SqList &l,intI,elemtype) { - if(i<1|| i>l.length+1)returnERROR;//I value is not legal the if(l.length==maxsize)returnERROR;//The current storage space is full - for(j=l.length-1; j>=i-1; j--) -l.elem[j+1]=L.ELEM[J];//insert position and after element move back -l.elem[i-1]=e; +l.length++; - returnOK; + } A //implementation of the delete algorithm atStatus Listdelete (SqList &l,inti) { - if(i<1|| I>l.length)returnERROR;//I value is not legal - for(j=i;j<=l.length-1; j + +) -l.elem[j-1]=L.ELEM[J];//the element that is deleted after the previous -l.length--;//table Length -1 - returnOK; in } - //disadvantage: belongs to the static storage form, the number of data elements cannot be freely expanded to

Basic operation of data structure 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.