{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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 first 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern