Find value find the position of x in the SeqList, return position of x in L, -1 if not found int Find( seqlist &l, listData x)i inti=0 while (i< Length & L data!=x) i++ if (i< Llength ) return 1; else return-l
▪ Find value:find the position of x in the SeqList,return position of x in L,-1 if not found. int Find ( SeqList &L, ListData x ) { int i = 0; while ( i < L.length && L.data[i] != x ) i++; if ( i < L.length ) return i; else return -1; }
Find value whether x is in L int IsIn( Seqlist &l, ListDatax) t inti=0, found=0 while(i< Llength &&l found if(L data!=x)i++ else found=l return found:
Find value:whether x is in L int IsIn ( SeqList &L, ListData x ) { int i = 0, found=0; while ( i < L.length &&!found ) if(L.data[i] != x ) i++; else found=1; return found; }
Solve the length of seq list int Length( Seq list &l)i return Length Find k th: return the k th data in ListData GetData( Seq list &l, int i)t if (i>=0&&i< Llength return Ldata; e print(“参数i不合理!Ⅶn”); eIs
◼ Solve the length of SeqList int Length ( SeqList & L ) { return L.length; } ◼ Find k_th:return the k_th data in l ListData GetData ( SeqList &L, int i ) { if ( i >= 0 && i < L.length ) return L.data[i]; else printf ( “参数 i 不合理!\n” ); }
Findsucceed int Next( Seq List &l, listData x)t int i= Find (x) if(i>0 & i< Llength )return i+1 else return-l FindPrevious int Next( Seqlist &l, listData x)i int i= Find(x); if(i>0 & i< Llength )return i-1 else return -l
▪ FindSucceed int Next ( SeqList &L, ListData x ) { int i = Find(x); if ( i >0 && i < L.length ) return i+1; else return -1; } ▪ FindPrevious int Next ( SeqList &L, ListData x ) { int i = Find(x); if ( i >0 && i < L.length ) return i-1; else return -1; }
■ Insertion 56 25345716480963 Insert x 50 D 34567 2534575016480963 The average moving number of times(AM if it is equal probability to insert the new element into all positions AMN- I ∑(n-i)=—(n+…+1+0) n+1 n+1 1n(n+1) (n+1)2
▪ Insertion 2 2 ( 1) ( 1) 1 ( 1 0) 0 1 1 ( ) 1 1 = n n n n n n i n n i n = + + = + + + = + − = + AMN 25 34 57 16 48 09 63 0 1 2 3 4 5 6 7 50 Insert x 25 34 57 50 16 48 09 63 0 1 2 3 4 5 6 7 50 i The average moving number of times(AMN) if it is equal probability to insert the new element into all positions