| CS 261 | University of Puget Sound | Spring, 2020 |
|
Computer Science II
|
||
|
Abstract Data Types and their Implementations,
Some Basic Algorithms,
Object-oriented Problem Solving, and Efficiency |
||
Warning:
This course is under development.
Although the basic structure of this course is largely established,
nothing on this Web site should be considered official or even possibly
correct.
DO NOT MAKE PLANS BASED ON THE CONTENTS OF THIS SITE UNTIL JANUARY, 2020.
The reading on doubly-linked lists describes an application involving the recording and retrieval of golf scores within a tournament. In that application, the golfer information is to be retrieved in each of the following ways:
Scores and names can be printed in order by ascending or by descending scores.
Given the name of a player, other players with the same score can be printed.
This lab asks you to implement a basic program for this application.
Following the reading on
doubly-linked lists, define a Golfer class
(similar to class NodeDouble in the reading), with
these elements:
public class Golfer {
private int score;
private String player;
private Golfer prev;
private Golfer next;
// appropriate constructors, getters, setters, and toString methods
Hint: Using menu options in Eclipse for the required methods should make this step quick and easy!
Write a class GolfTournament with these elements:
Fields
Golfer first;
Golfer last;
A constructor that initializes a list
to null.
Note both the first and last fields will
need to be set to null.
An insert method that reads a golfer's name and score
and inserts a new node into the list for that golfer,
so that the list is ordered by golf score.
Hint: A similar insertion process for singly linked
lists was part
of previous lab on
[singly-] linked lists (Phase 2).
Methods, printForwards and printBackwards, that print all nodes on the list from front to back or back to front, respectively.
A printSameScores (String name) method that searches the list for a node containing information for the golfer with that name and then prints all golfers who had that same score.
Note: Since nodes are ordered by score, once a golfer's node is identified, then all other golfers with that score can be obtained by moving from the given node backward and then forward, always looking for more golfers with the same score.
|
created 28 January 2020 revised 28 January 2020 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. class="footer-a"tr> |