
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















▪ (^) add(9); current position is 3. The new list would thus be: (2, 6, 8, 9, 7, 1) ▪ (^) We will need to shift everything to the right of 8 one place to the right to make place for the new element ‘9’. curre nt 3 siz e 5 step 1:
1 2 3 4 5
6 curre nt 4 siz e 6 step 2:
1 2 3 4 5
6
notice: current points to new element
curre nt 4 siz e 6
1 2 3 4 5
6
5
a. past the last array cell b. before the first cell
curre nt 5 siz e 6
1 2 3 4 5
6
5 Step 1: curre nt 5 siz e 5
1 2 3 4 5 Step 2 9 2:
find(X): traverse the array until X is located. int find(int X) { int j; for(j=1; j < size+1; j++ ) if( A[j] == X ) break; if( j < size+1 ) { // found X current = j; // current points to where X found return 1; // 1 for true } return 0; // 0 (false) indicates not found }
▪ (^) Worst-case: remove at the beginning, must shift all remaining elements to the left. ▪ (^) Average-case: expect to move half of the elements.
▪ (^) Worst-case: may have to search the entire array ▪ (^) Average-case: search at most half the array.
object nex t
2 6 8 7 1 hea d curre nt size= 5