Programming Assignment 1

Linked-Sequence ADT Animation

Data Structures & Algorithms, Fall 2010


Due Date

This assignment is due by 11:30 p.m. on Wednesday, 20 October.

See the assignment turn-in page (last modified on 23 February 2010) for instructions on turning in your assignment.

The absolute deadline for turning-in Assignment 1 is Saturday, 23 October at 11:30 p.m.. It is not possible to turn-in Assignment 1 after the absolute deadline.

Background

A linked sequence ADT is a family of data structures representing value sequences. Adjacent values in a linked sequence are directly linked; non-adjacent values are not linked.

a linked sequence

The links in a sequence are numbered sequentially starting from zero at one end of the sequence; the end values in a sequence are assumed to have links on both sides.

link indexing

An empty sequence is assumed to have one link.

an empty sequence

A value v in a linked sequence is referred to by the index associated with v's left link (or, if you prefer, the smaller of the two index values directly associated with v). Operations on values in a linked sequence are specified relative to link indices.

linked-sequence operation examples

The stack, queue, and linked list ADTs are members of the linked-sequence ADT family. They differ in the range of indices their operations can accept:

In terms of the number of legal indices accepted by their operations, stacks are most restrictive, linked lists are least restrictive, and queues are less restrictive than are stacks and more restrictive than are linked lists.

The Assignment

This assignment has two parts.

Part 1: Implement the stack, queue and linked list ADTs. Each ADT should be a separate class implementing the linked-sequence interface given in

/export/home/class/cs-305/pa1/LinkedSequence.java
Call your ADT classes anything you like, and implement any other ADT class methods you think necessary (for example, you may need constructors, or want to add some testing methods). You may implement any other helper classes you think necessary.

The implemented ADTs should dynamic, capable of storing arbitrarily many values. The implementations should be from scratch, without using classes from the Java Collection library.

Part 2: Implement a class implementing the LinkedSequenceByExample interface given in

/export/home/class/cs-305/pa1/LinkedSequenceByExample.java
As with the linked-sequence ADTs, you may call the implementing class anything you want, and implement any other methods and helper classes you think necessary.

Implementation

The classes created for the first assignment should be placed in the default package. Classes are placed in the default package when the Java source code does not use package declarations. Using package declarations in Java source code places class files in non-default packages, and the turn-in software, expecting the class files to be in the default package, won't be able to find them.

Once you’ve got your implementation far enough along, you can try it out using the jar file
/export/home/class/cs-305/pa1/pa1.jar
by typing

$ java -classpath jar-path/pa1.jar:. main class-name

where jar-path is the path to pa1.jar and class-name is the name of the class implementing the LinkedSequenceByExample interface. For example, if the class ADTs implements LinkedSequenceByExample and you’re using pa1.jar in the public class directory, you would type

$ java -classpath /export/home/class/cs-305/pa1/pa1.jar:. main ADTs 

Make sure you give the class name (ADTs in this example) on the command line, not the name of file containing ADTs (ADTs.class).

You can simplify your typing a bit by copying pa1.jar to your working directory ( . ):

$ cp /export/home/class/cs-305/pa1/pa1.jar .

$ java -classpath ./pa1.jar:. main Queue

If you do copy pa1.jar, make sure you keep it up to date with version in the class directory. You can check jar file j’s version by typing

jar tf j | grep 2010

For example,

$ jar tf /export/home/class/cs-305/pa1/pa1.jar | grep 2010
2010.Sep.29

$ 

The recognized optional command-line options are:

Command-line options should be given after main and before the generator class; for example

$ java -ea -cp pa1.jar:. main LinkedADTs
Test failed:  requested a queue, got a stack.

$ java -ea -cp pa1.jar:. main -v LinkedADTs
Request a queue.
Test ADT as a linked list.
  (put, 0, 1, true, undefined) : passed.
  (put, 1, 3, true, undefined) : ADT failed on this action.
Test ADT as a queue.
  (put, 0, 1, true, undefined) : passed.
  (put, 1, 3, true, undefined) : ADT failed on this action.
Test ADT as a stack.
  (put, 0, 1, true, undefined) : passed.
  (put, 1, 2, false, undefined) : passed.
Test failed:  requested a queue, got a stack.

$


This page last modified on 15 October 2010.