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