Question: Develop a new stand-alone generic class , called StackYourname , to implement, among others, key stack operations [ push(e), pop(), peek(), size(), isEmpty() ]we discussed
Develop a new stand-alone generic class, called StackYourname, to implement, among others, key stack operations [push(e), pop(), peek(), size(), isEmpty()]we discussed in the class. Note that our LinkedList class does not use variable size, but you can use variable size in this class StackYourname. Again, class Stack needs to be defined as generic stack with type
Furthermore, define class Node as part of class Stack, similar to class LinkedList in the previous assignment.
StackYourname Class must have these methods
- methodname(argument): return type
- isEmpty(): Boolean Returns true if this stack is empty
- size(): int Returns the number of elements in this stack
- peek(): E Returns the top element in this stack
- pop(): E Returns and removes the top element in this stack
- push(E element): E Adds a new element to the top of this stack
- search(E element): int Returns the position of the specified element in this stack
- toString(): String Returns the String with all elements in current stack
Part 2: (10 points)
Next, develop a simple test program called TestStackYourname, similar to that you developed in the previous assignment, to test each stack operation listed above and defined in your class Stack. Use integer type stack for the test program. Organize the outputs of this test program similar to that of test linked-list, where you need to show the stack content before and after calling a stack operation. Use proper labels. Please DO NOT hard-code test data. Make sure to allow the user to enter the stack content using interactive menu (embedded inside the sentinel loop):
-----MAIN MENU----- 0 - Exit Program 1 - Push 2 - Pop 3 Peek (Top) 4 - Size 5 Is Empty? 6 - Print Stack
Again, you cannot change method names, return type and parameter types.
To evaluate your Classs methods, the instructor will use another Test Program and will use your methods.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
