cs631hw4solutions

cs631hw4solutions - CS631 Homework 4 solutions 1 Convert...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS631 Homework 4 solutions 1. Convert LinkedList class to use object rather than integer. This is posted to the class web page under Lab and Example Code, Homework folder. The key was replacing int by Object in the LinkedList and node classes. Also key were how to put integers in and out of the list: • Putting them in – box a primitive int in a new Integer. L.addFirst(new Integer(37)); • Taking them out – use the fact all Objects have a “toString” method so we don’t really have to know that they are integers to print them. System.out.print( " " + current.getInfo().toString()); If we did, we would have to cast them back to Integer with this line: int I = ((Integer)current.getInfo()).intValue(); 2. Page 283, #4. Delete the maximum value from a linked list. Posted to the class web page under Lab and Example Code, Homework folder. Yes, you can delete an item on a single traversal of the list with the expense of maintaining a following pointer, called “maxprev” in the code. In general, you want to save time by minimizing the number of times pointer, called “maxprev” in the code....
View Full Document

This note was uploaded on 10/21/2009 for the course CS CS 631 taught by Professor Dr.rogerd.eastman during the Spring '09 term at Loyola Maryland.

Page1 / 2

cs631hw4solutions - CS631 Homework 4 solutions 1 Convert...

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