HW4 - it is present in the second list. Question 9. (10...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
University of California, Santa Barbara CS20, Spring 2008 Homework IV solutions Question 1. (10 points) a) 1 0 4 5 16 0 3 b)6 4 6 0 0 5 0 Question 2. (10 points) a)i.True b)ii.False c)i.True Question 3. (30 points) a)2112 b)10/02/2001 Question 4. (10 points) (a)No change. (b) Front will never point to the new Node, the new node will point to intself and we lose access to the whole queue except the last element. (c)No effect. (d) If the queue has more than one element, we will get the info of second element instead of first. If the queue has only one element, we will get a null pointer exception. Question 6. (5 points) 6.19. We just need to call the method ”contains(o) for each Object o that we are adding, and only add if that method returns false. 6.20. The same above. Question 7. (10 points) Unsorted apple pear orange Sorted 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
apple orange pear Indexed pear orange plum Question 8. (10 points) (a) The algorithm should simply iterate through the first list and for each element check whether
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: it is present in the second list. Question 9. (10 points) (b) We can create a new List (call it result list), then each time compare the rst element of the currnet list and given list, and puts the smaller to the next empty slot of the result List, after that, we should remove that element from its original List. After one of the lists becomes empty, we just copy the remaining contents of the other list to the result list. Note that adding elements to the result list just adds them to the end of the list and we do not need to search for the appropriate place because we are coping element in the increasing order. Question 10. (15 points) We have to iterate throught all elements anyways becasue we do not have the linke of the node in the middile of the list and inorder to get it we need to iterate through the elements before it. 2...
View Full Document

This note was uploaded on 10/02/2009 for the course CS 20 taught by Professor Agrawal during the Spring '08 term at UCSB.

Page1 / 2

HW4 - it is present in the second list. Question 9. (10...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online