Handout2 2 - // // pre : post: I^ capacity constructs ct an...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // // pre : post: I^ capacity constructs ct an I i nt_ empty l_ist with r 1 the given capacity '-,,Lr yuurru ^ *_^-,rnl_T,i nllayr - a n _ ^ .r tL y / f , , \ __/du el-ement.Data q i za nt . v new int Icapacity ; t returns / / post: the public int size () { return size; ) current number of el-ements in the list // pre : 0 returns / / post: the integer public int get (int index) { return elementData Iindex] ) // post: if l al at ; the given index in the Iist creat.es (Frina rLr!rrY a comma-separated, \,/ f I bracketed version of the Iist nrrl.rlin re IJuvf lL- v J L !- !rri rngn / \ ^q1 (size return eo tt 0) { t'"; 'r String result Irr + elementDat.a IO ] ; (int for i: L; i < size; i++) resu.l_t +: ',, 't + el-ementData Ij- ] ; + : t t . ]" i result ret.urn result i ) l : returns the position / / post of the ( 1 :f ;-)u; :-::r- foun:..) ,'/ public int indexOf(int value) { for(int i : 0; i < size; i++) (el-ementDataIi] if val_ue) return r; -L; return ) pre < capacity (elementData.length) : sizeO // given appends the / / post: value to the end of public void add (int val_ue) { : value; elementData Isize1 q 1 zo++. first occurrence of the given the list ) //pre:size()<capacity(eIementData.Iength)eeO<:index<= // nnqf. inqorts Fhe oj ri v vr re n rr : v s r fq s u e va at qL tUh te lg crirren !JrvLrr rrlgg^, indp:<. .shiff _--- .ino 1 s vrei h q e c r r r o n t _ va.Lues right // public void add(int index, int value) (inti:size; for i>index; i--) elementDatalil elementDataIi : va]ue; elementDataIindex] i ze++; s ) pre :0 // post: // removes value pubJ rc void remove (t-nt -f;i- (;nt _t : rndex; elementDataIi] Q'2e-- { L) ; at the given index, shifting :-ndex) t - 1; i_++) -i < si;e + Il; elementDatali subsequent vaiues Left / ' ...
View Full Document

Ask a homework question - tutors are online