COMP 1020 Midterm: COMP1020 Exam 2014 Spring

328 views9 pages
lavenderbeaver188 and 10 others unlocked
COMP 1020 Full Course Notes
12
COMP 1020 Full Course Notes
Verified Note
12 documents

Document Summary

Cs1020 - data structures and algorithms i - may 2014. Section a (6 multiple choice questions: 18 marks) Arraylist arr = new arraylist(); for (int i=0; i<10; i++) arr. add(i); for (int i=0; i 0) { recurse(n--); How many lines will be printed in the output? (a) 5 (b) 6 (c) 7 (d) 12 (e) none of the above. Cs1020: consider the following program: import java. util. public class test2 { public static void main(string[] args) { int[] array = new int[] {1,2,3,4,5}; Stack s = new stack(); for (int i: array) { s. push(i); if (i%2 == 0) s. pop(); Queue q = new linkedlist(); for (int i: array) { q. offer(i); if (i%2 == 0) q. poll(); Suppose we have just finished the first partitioning and the pivot swapping to result in the following content in the array: