ITI 1121 Midterm: ITI 1121 University of Ottawa 2003 Midterm-en
Document Summary
Question 1 (38 marks) (a) write an interface called pair. A pair represents a group of two elements. The interface must contain the following methods: object getfirst(), object getsecond(), void swap(); Page 3 of 15 (b) write a linked-list implementation for the abstract data type pair. The class linkedpair must have an instance variable called rst to designate the rst node of the linked-list. Write a constructor with two parameters, both of type object, that are used to initialize the rst and second elements of the list. Write all the necessary methods so that linkedpair implements the interface pair. boolean equals(object obj) Page 5 of 15 (c) write an array-based implementation for the abstract data type pair. This class, called arraypair, must implement the interface pair and use an array to store its elements. The class arraypair must have an instance variable called elements to designate an array of two elements. No other instance variable is necessary or allowed.