I have added a little Code but I need help with the rest.
/**
A class of stacks whose entries are stored in a chain of nodes.
Implement all methods in MyStack class
Main Reference : text book or class notes
Do not change or add data fields
*/
package PJ2;
public class MyStack<T> implements StackInterface<T>
{
// Data fields
private Node<T> topNode; // references the first node in the chain
private int numberOfEntries;
public MyStack()
{
topNode = new Node<T>();
numberOfEntries = 0;
// add stataments
} // end default constructor
public void push(T newEntry)
{
if(empty()){topNode.setData(newEntry); // add stataments
numberOfEntries++;
}
Node<T>nextNode = new Node<T>();
//set data
//attach it to top node
//increment numberOfEntries
} // end push
public T peek()
{
// add stataments
return null;
} // end peek
public T pop()
{
return null;
} // end pop
public boolean empty()
{
if(numberOfEntries == 0){return true;
}
else{return false;}
// add stataments
} // end empty
public int size()
{
// add stataments
return 0;
} // end isEmpty
public void clear()
{
// add stataments
} // end clear
public String toString()
{
// add stataments
return "";
}
/****************************************************
Do not modify: Stack test
Expected output:
OK: stack is empty
Push 3 data: 10, 30, 50
Print stack [50,30,10,]
OK: stack size is 3
OK: peek stack top is 50
OK: stack is not empty
Pop 2 data: 50, 30
Print stack [30,10,]
Print stack [10,]
OK: stack pop data is 30
Clear stack
Print stack []
******************************************************/
public static void main (String args[])
{
MyStack<Integer> s = new MyStack<Integer>();
if (s.empty())
System.out.println("OK: stack is empty");
else
System.out.println("Error: stack is not empty");
s.push(10);
s.push(30);
s.push(50);
System.out.println("Push 3 data: 10, 30, 50");
System.out.println("Print stack " + s);
if (s.size() == 3)
System.out.println("OK: stack size is 3");
else
System.out.println("Error: stack size is " + s.size());
if (s.peek() == 50)
System.out.println("OK: peek stack top is 50");
else
System.out.println("Error: peek stack top is " + s.size());
if (!s.empty())
System.out.println("OK: stack is not empty");
else
System.out.println("Error: stack is empty");
System.out.println("Pop 2 data: 50, 30");
s.pop();
System.out.println("Print stack " + s);
int data=s.pop();
System.out.println("Print stack " + s);
if (data == 30)
System.out.println("OK: stack pop data is 30");
else
System.out.println("Error: stack pop data is " + data);
System.out.println("Clear stack");
s.clear();
System.out.println("Print stack " + s);
}
} // end Stack
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
I have added a little Code but I need help with the rest. /** A class...
Java. Must not use Java API java.util.Stack /** A class of stacks whose entries are stored in an array. Implement all methods in ArrayStack class using resizable array strategy, i.e. usedoubleArray() Must throw StackException during exception events in methods: peek(), pop(), ArrayStack(int initialCapacity) Do not change or add data fields Do not add new methods */ import java.util.Arrays; public class Arraystack«Т> implements Stack!nterface«T> private TI stack;// Array of stack entries private int topIndex; /7 Index of top entry private static...
Java. Must not use Java API java.util.Stack /** A class of stacks whose entries are stored in an array. Implement all methods in ArrayStack class using resizable array strategy, i.e. usedoubleArray() Must throw StackException during exception events in methods: peek(), pop(), ArrayStack(int initialCapacity) Do not change or add data fields Do not add new methods */ import java.util.Arrays; public class Arraystack«Т> implements Stack!nterface«T> private TI stack;// Array of stack entries private int topIndex; /7 Index of top entry private...
Java - data structures Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the...
help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...
I was told I need three seperate files for these classes is there anyway to tie all these programs together into one program after doing that. I'm using netbeans btw. import java.util.ArrayList; import java.util.Scanner; /** * * */ public class MySorts { public static void main(String[] args) { Scanner input = new Scanner(System.in); String sentence; String again; do { System.out .println("Enter a sentence, I will tell you if it is a palindrome: ");...
Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException at InfixExpression.execute(InfixExpression.java:98) at InfixExpression.Evaluate(InfixExpression.java:65) at InfixExpression.setWholeExpr(InfixExpression.java:24) at InfixExpression.<init>(InfixExpression.java:17) at Main.testHW1(Main.java:17) at Main.main(Main.java:6)" I need to get this as my output: "Testing InfixExpression: When passing null, the String and double = Infix String: , result: 0.0 When passing a valid String, the String and double = Infix String: ( 234.5 * ( 5.6 + 7.0 ) ) / 100.2, result: 29.488023952095805 ..." I...
JAVA LANG PLEASE: I have follwed these below guidelines but when i run my queue test it is not executing but my stack is working fine, can you fix it please! MyQueue.java Implement a queue using the MyStack.java implementation as your data structure. In other words, your instance variable to hold the queue items will be a MyStack class. enqueue(String item): inserts item into the queue dequeue(): returns and deletes the first element in the queue isEmpty(): returns true or false...
I need to modify my C++ code so it can get the min value of the stack code is as follows: #include <iostream> using namespace std; #define MAX_SIZE 100 class Stack { private: int S[MAX_SIZE]; int top; public: Stack() { top = -1; } void push(int x) { if (top == MAX_SIZE - 1) { cout << "Stack is Full." << endl; return; } S[++top] = x; } void pop() { if (top == -1) { cout << "Stack is...
how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 } class Stack { Node head; int size; Stack() //default constructor { this.head=null; this.size=0; } //Input = data //Output = void (just adds value to list) // method pushes elements on stack // time: O(1) // space: O(1) public void push(int data) { Node node=new Node(data); node.next=head; head=node; size++; } //Input = none //Output = top of stack // method pops value from top of...
how would I complete this code without calling any built-in java collection framework classes like ArrayList, LinkedList, etc? import java.util.Iterator; class CallStack<T> implements Iterable<T> { // You'll want some instance variables here public CallStack() { //setup what you need } public void push(T item) { //push an item onto the stack //you may assume the item is not null //O(1) } public T pop() { //pop an item off the stack //if there are no items on the stack, return...