Objective: The purpose of this exercise is to create a "Stack" LIFO data structure that mimics the behavior of the Java

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Objective: The purpose of this exercise is to create a "Stack" LIFO data structure that mimics the behavior of the Java

Post by answerhappygod »

Objective: The purpose of this exercise is
to create a "Stack" LIFO data structure that mimics the behavior of
the Java Standard Library Version (Java API). The outcomes/results
of using the library features should be identical with your own
version (My API). However, the underlying implementation should
follow with the descriptions listed below.
Testing your skills.
Now that you have tested your data structure making strategies.
You have already been introduced to Stacks in Practice It, now you
will design and implement your own Stack and Queue data
structures.
Instructions : Create a Stack class using
"singly linked" nodes. NOTE: This
is not saying the implementation is using a
"singly linked" Linked List! Notice the
difference between a "Linked List" and a "Linked Data
Structure".
Key Points
Where to find starter code in my-api
package.class : utils.MyStack
Where to find the test starter code in
my-api
package.class : tests.console.MyStackTest
Where to find the JUNIT TEST code in my-api
package.class : tests.junit.MyStackJUnitTest
Task Check List
Design Description : Building A Stack Data
Structure
Create a generic class for a "Stack" data structure (LIFO) with
the following methods:
string representation: displays the
contents of the stack. Create a string representation of the stack
from top (last) to bottom (first) reading left to right.
Note: Changes will be made to how this content is displayed in a
future lab.
MyStack<E>
outer class: Create the generic
MyStack<E> class. This is used to control the linked node
structures.
data fields:
constructor: uses a default constructor to
initialize the data fields.
public MyStack()
outer class methods: your methods should
follow the input and output requirements in the Java Standard
Library. NOTE : All methods must be implemented.
Deductions apply otherwise.
Method
Description
Example
detach
removes the node at the top of the stack and returns removed
item. This is a private helper method.
private Edetach()
push
places given element on top of stack.
public E push(E item)
pop
removes the element at the top of the stack and returns it.
Throws
an EmptyStackException, if
stack is empty.
public E pop()
peek
returns the element at the top of the stack without removing it
from the stack. Throws
an EmptyStackException, if
stack is empty.
public E peek()
size
returns number of elements in stack.
public int size()
isEmpty
checks if stack is empty and returns true, if stack has no
elements.
public boolean isEmpty()
NOTE : All methods must be implemented. Deductions apply
otherwise.
inner class: class inside the body of another
class.
The outer class MyStack class includes a nested static generic
Node<E> class, i.e. a static
inner class within the Linked List
class. Note: This private class does not require
access to instance members of the outer class, so it is
declared static. This means that the node object
won’t be coupled to the outer class object, and hence will be more
optimal ...since it won’t require additional heap/stack memory.
data fields:
constructor:
A constructor that receives parameters for data, next and
prev.
public Node( E data,
Node<E> next,)
PLEASE POST THE FULL INPUT OF THE CODE AND OUTPUT!!!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply