Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create a generic abstract class called GenericList<I>:
- This class will contain only two data fields:
- Node<I> head (this is the head of the list).
- int length (the length of the list and should be private)
- This class should include the following methods:
- print(): prints the items of the list, one value per line.
- add(I data): adds the value to the list. This is abstract since the implementation
- depends on what the data structure is.
- delete(): returns the first value of the list and deletes the node.
- This class should also define a generic inner class Node<T>: It will include two fields: T
- data and Node<T> next;
- ***This class encapsulates a linked list. Defining a Node class and providing two
- methods that a queue and stack have in common while leaving adding a node to each
- implementation that inherits from it.***
- Create two more classes GenericQueue<I> and GenericStack<I>. They both should
- inherit from GenericList<I>.
- The constructors for each class will take one parameter. That parameter will be a value
- that will go in the first node of the list encapsulated by each instance of the class. Each
- constructor should initialize the linked list head, with the value passed in by the
- constructor. Each class should also implement the method add(I data), GenericQueue
- will add to the back of the list while GenericStack will add to the front. Each class must
- also keep track of the length of it’s list using the length data field defined in the abstract
- class.
- GenericQueue will have the methods enqueue(I data) and dequeue() which will call
- the methods add(I data) and delete() respectively. Enqueue and dequeue merely call
- add(I data) and delete(). The reason for this is that a user would expect these calls to
- be implemented in each of those data structures. You will do the same with GenericStack.
- GenericStack will have the methods push(I data) and pop() which will call the
- methods add(I data) and delete() respectively.
- Once implemented, you should be able to create instances of both GenericQueue and
- GenericStack in main with most primitive wrapper classes. You should be able to add
- and delete nodes to each data structure instance as well as print out the entire list and
- check for the length of the list. You must follow this implementation: meaning you can
- not add any additional data fields or classes. You may add getters/setters as need be.
- Implementing Iterator Design Pattern:
- You are to create an interface called CreateIterator. It will have one abstract method:
- Iterator createIterator(). You will want both GenericQueue and GenericStack classes
- to implement this interface.
- You must also create a class to contain logic for iterating through your data structure.
- Call this class GLIterator.
- It should implement the java interface Iterator (java.util.Iterator). You will have to
- implement two inherited methods: hasNext() and next().
- You are expected to fully comment your code and use good coding practices.
Add Comment
Please, Sign In to add comment