3. 3 Formula-based Representation Program 3. 4 template <class t> LinearList <T>& linearlist <t>: Delete( int k, T& x) i if (find(k, x)) f for( int i=k; i<length; 1++) element[i-1=element[[] length return * this else throw OutofBoundso
3.3 Formula-based Representation Program 3.4 template <class T> LinearList <T>& LinearList <T>::Delete( int k, T & x) { if (Find(k,x)) { for ( int i=k; i<length; i++) element[i-1]=element[i]; length--; return *this; } else throw OutOfBounds() }
3.3 Formula-based Representation 5) insert (int k, const T&x insert x after the k'th element L=(a, b, c, d, e, g) insert(0, h=>L=(h, a,b, c, d, e,f gl index of a, b, c, d, e,f, and g increase by 1 insert(10, h) error insert(-6, h)=> error
3.3 Formula-based Representation 5) insert (int k, const T&x) insert x after the k’th element L = (a,b,c,d,e,f,g) insert(0,h) => L = (h,a,b,c,d,e,f,g) index of a,b,c,d,e,f, and g increase by 1 insert(10,h) => error insert(-6,h) => error
3.3 Formula-base representation Program 3.5 template <class T LinearList <t> &linearlist <t>: insert(int k, const T&x) i if (k<o k> length) throw OutofBoundso if length==MaxSize) throw NoMemo for (int i-=length-1; i>=k; i--) element[i+1=element[] element[ k]=X length++ return *this
3.3 Formula-base Representation Program 3.5: template <class T> LinearList <T> &LinearList <T>::insert(int k, const T &x) { if (k<0 || k> length ) throw OutOfBounds(); if ( length = = MaxSize) throw NoMem(); for ( int i= length-1; i>=k; i--) element[i+1] = element[i] ; element[k] = x ; length++; return *this; }