c17f06t2

c17f06t2 - CSE 17 Test 1 Friday 17 November 2006...

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

View Full Document Right Arrow Icon
CSE 17 Test 1 Friday 17 November 2006 <<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>> 1. Assume the following class: public class Node{ public int j; public Node next; } Write a method list() for listing the contents of a linked list of Nodes in the file "test2.out". Given Node hd;, where hd points to a linked list that terminates in a null pointer, the call list(hd,"test2.out") should list the contents of the linked list in the file "test2.out". <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< public static void list(Node hd,String file){ try{ PrintWriter out=new PrintWriter(new FileOutputStream(file)); while(hd!=null){ out.println(hd.j); hd=hd.next; } out.close(); }catch(FileNotFoundException e){ System.err.println("The file 'afile.out' could not be opened"); System.exit(1); } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Write an abstract class Bound, that requires its subclasses to have functions max() and min() that are meant to return the largest
Background image of page 1

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

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

Page1 / 2

c17f06t2 - CSE 17 Test 1 Friday 17 November 2006...

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