Implement and test a directed graph in Java.
Use it to compute a topological sort for an input graph.
Details here.
You may use the Java Collections library for this assignment.
You may want lists or queues, etc.
Write your own graph and toposort code.
Implement and test a Splay Tree (SPLT) in Java.
Details here.
Do not use the Java Collections library for this assignment.
You don't need lists or queues, etc.
Write your own cell and tree code.
Implement and test a Minimum Binary Heap (BHEAP) in Java.
Details here.
Do not use the Java Collections library for this assignment.
It is array based, so you don't need lists or queues, etc.
Write your own heap code.
Implement and test a Binary Search Tree (BST) in Java. Details here.
For this assignment use Java. Do not use the Java libraries for LIST and QUEUE. Write all your own code.
Create a Java program that uses the Bridge design pattern to build and exercise QUEUE of String with 2 different implementations (array, and linked cells). We are actually going to do this by
new: --> QUEUE enq: QUEUE x String --> QUEUE deq: QUEUE --> QUEUE front: QUEUE --> String size: QUEUE --> int empty: QUEUE --> booleanThis is the collection of methods the front end will offer. Note that they are "queueish" method names.
On the backend will be a general list, with these methods:
new --> LIST ins: LIST x String x int --> LIST rem: LIST x int --> LIST get: LIST x int --> String size: LIST --> int empty: LIST --> booleanNote that this has "list-ish" method names. Note also that you do not need to implement the "find" operation on LIST, as there is no corresponding capability in QUEUE. However, the "get" operation will be needed for implementing the "front" operation in QUEUE.
These functional signatures are like what we saw for the abstract ML axiom definitions. Now that we are going to build them in Java, you will have to "objectify" the methods... for example
new: --> QUEUE will become a constructor for class Queue, like Queue( ) { ... } and enq: QUEUE x String --> QUEUE will become a void method in class Queue like this void enq ( String val ) { ... }
Follow the stack example I gave for the bridge pattern, except (of course) you will do queues instead of stacks. The client side class will be QUEUE of String and that class will have the methods shown above for QUEUE. This client-side QUEUE object will also contain a reference to a backend implementation object (a LIST using either array or links). Calls to the QUEUE operations will be implemented by calling in some appropriate way operations in the implementation LIST object.
The backend implementation will have an interface that will define the common operations in LIST (shown above). You then create subclasses (implement the interface) for each of the LIST implementation methods: one for an array-based version of LIST and another for the linked cells version of LIST.
Build your program by filling in this rough outline. It basically is setting up the bridge, and making clear the distinction between the abstraction side (QUEUE) and the implementation side (LIST).
Your main program will be a test driver that will create one of each kind of QUEUE (a QUEUE with an array list implementation, and a QUEUE with a links list implementation). Do these steps:
Here is an example. Let's assume the command line args are these:
greek alpha beta gammaThe output should look like this:
1 1 greek greek 0 0 alpha alpha 2 2 beta beta 1 1 gamma gamma 0 0The output will be symmetrical like this if both implementation methods are correctly providing the QUEUE behavior.
BQUE of E new: pos -> BQUE (here, pos is int > 0) enq: BQUE x E -> BQUE deq: BQUE -> BQUE front: BQUE -> E size: BQUE -> nat (naturals, int >=0 ) max: BQUE -> pos empty: BQUE -> boolean full: BQUE -> booleanAs with the LIST definition, make sure to supply ML code that tests the specs to make sure they are correct.