QuestionQuestion

Part 1 - MyStack.java

Create a Stack class named MyStack.java that stores data of type T (generics?) . Specifically, implement push(T), pop(), peek(), size(), and isEmpty. You must use a linked list with a sentinel node - include a separate Node.java class with your submission.

Part 2 - MyStackFunctions.java

Create a StackFunctions class that accomplishes the following as static methods:

sumNegative : Given a MyStack of Integers, sums and returns the total of all negative values in the stack as an int. For example, a stack containing 5, -1, -2, 3, and -20 would result in a return -23. The input stack should be in its original state at the end of the method call (you will need to push things back onto the input stack carefully after processing, I suggest using a 2nd stack variable).

clean : Given a MyStack of Strings, splits all Strings in the MyStack with spaces into multiple Strings in the stack. For example, a StackADT of "Bob", "Jim is home", and "Hello World" would be changed to "Bob", "Jim", "is", "home", "Hello", and "World". Order of the items on the stack does not matter but you should alter the MyStack passed as a parameter (you can then return the stack or have a void return type). (maybe use String class's split() method?)

main : Does two example runs of each of sumNegative and clean on different input MyStacks for each example (so a total of 4 MyStacks, 2 MyStack<Integer> and 2 MyStack<String>).

Language: Java
Compiler: Eclipse

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class MyStack<T> {

private Node<T> head;
private int size;

public MyStack()
{
head = null;
size = 0;
}

public void push(T data)
{
Node<T> newNode = new Node<T>();
newNode.data = data;
newNode.next = head;
head = newNode;
size++;
}

public T pop()
{
Node<T> temp = head;
if(head != null)
{
head = head.next;
size--;
return temp.data;
}
return null;
}

public T peek()
{
if(head != null)
return head.data;
else
return null;
}

public int size()
{
return size;
}

public boolean isEmpty()
{
return size==0;
}
}...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats