Lab 4:

1) Using the Sequence ADT

  • Study the doubly linked-list implementation of the Sequence ADT present in NodeSequence.java and NodeList.java
  • In Sentence.java
    • Use the Sequence sentence to store words and create phrases.
    • Use the Sequence ADT methods to modify this sequence to output the text below.
    • Use the printSentence(Sequence sentence) method to print the content of the sentence (for each phase in the output).
      • Example:

       sentence.insertFirst("This ");
       sentence.insertLast("sentence.");   ===>   "This sentence."
       printSentence( sentence );

    • Try to use as many different methods as possible
  • Compile and run Sentence.java


> java Sentence
--------------------------------------------------------------------------------
This sentence.
This sample dumb sentence.
This dumb sample sentence.
This is a sample sentence.
This is a sentence.
This is a self-referential sentence.

The sentence is now empty.

Let's end by throwing an exception:
Exception in thread "main" InvalidPositionException: Position does not belong to
a valid NodeList
        at NodeList.checkPosition(NodeList.java:31)
        at NodeSequence.rankOf(NodeSequence.java:34)
        at Sentence.main(Sentence.java:56)
--------------------------------------------------------------------------------
 

2) Recursion: Hanoi. Exercise C 47 from your textbook.

    - Try the game first. here

    - The recursive pseudo code for the solution. here

    - The java class for the solution. here

    - Test class with 5 disks to be moved from 1 to 3 using 2.

 

Extra 

3) Exercise 5.7 from your text book. Sequence ADT extension