CSE 109 Test 2 SPRING 2007

CSE 109 Test 2 SPRING 2007 - CSE 109 Test 1 Wednesday 11...

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: CSE 109 Test 1 Wednesday 11 April 2007 <<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Assume the definition of class Link below, meant to be used to construct a linked list ending in a NULL pointer. Overload the operator "<<" such that the code below the definition of Link would display the linked list in the following form: 6-->4-->3-->NULL class Link{ public: int j; Link *next; }; Link * t; //some code to build the list cout<<t<<endl; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ostream & operator<<(ostream &out,Link *k){ while(k!=NULL){ out<<k->j<<"--> "; k=k->next; } out<<"NULL"; return out; } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Write a template for the class Comaprable that stores an instance of some variable for which "<" is defined. Instances of the class should respond to the methods min() (max()) by returning an instance of Comparable containing the value from the smaller (larger) of two instances. For example, the code below should produce the indicated output. Comparable <int> a(5),b(3); cout<<a.min(b)<<" "<<a.max(b)<<endl; // [3] [5] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...
View Full Document

This note was uploaded on 05/05/2008 for the course CSE 109 taught by Professor Kay during the Spring '08 term at Lehigh University .

Page1 / 4

CSE 109 Test 2 SPRING 2007 - CSE 109 Test 1 Wednesday 11...

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