COMP 250 Study Guide - Final Guide: Linked List, Tree Traversal, Hash Table

105 views13 pages

Document Summary

The exam is 14 pages, including this cover page. There are 10 questions, worth a total of 60 58 points. Answer all questions on the exam question sheet. An extra page is included at the end for sketching out solutions. Comp 250: (4 points) (a) fill in the missing code in the indicated region /**/ for the following method in a. The method should remove and return the list element at index i. State any assumptions you make about the private elds of the class. public. T tmp; if ((index >= 0) && (index < size)){ ------- solution begin------------------------ assume a private field array[] tmp = array[index]; for (int j=index; j < size-1; j++){ array[j] = array[j+1]; // error if size==length will give size--; return tmp; Took o 0. 5 for an o -by-one error in the upper index e. g. size instead of size-1 Took o 0. 5 for forgetting to decrement the size eld.