Need help in java with some of these methods. I have also provided the first part of code in case it helps, but again I

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

Need help in java with some of these methods. I have also provided the first part of code in case it helps, but again I

Post by answerhappygod »

Need help in java with some of these methods. I have alsoprovided the first part of code in case it helps, but again I justneed help with these methods. Please leave comments or anexplanation. The goal is to implement a simple undo/redo stackusing dynamically resizing array, in which, the stack will only berequired to take in String's. The method I need help implement arethe following:
redo(): Returns the last thing popped from the stack andplaces it back in the stack if a push method is called after a popthe redo will empty and not do anything. Returns true if somethingis added to the main stack, false otherwise. Make sure to allowmultiple things to be redone, place objects popped into a redostack. This stack should also be dynamically resizing.
clear(). – clears the stack and makes the array holding thestack a size of 0, as well as clearing the redo variable.
concatenateStack(stack) – will concatenate thestacks, with the items in the stack being called on being atthe bottom of the stack and the items in the parameter stack beingon the top of the stack, then save it to the stack being calledon.
import java.util.Arrays;
public class ArrayStack implements ArrayStackInterface {
private String[] data = new String[0];
private String[] redo = new String[0];
private void growData() {
var newStack = Arrays.copyOf(data, data.length +1);
data=newStack;
}
private void shrinkData() {
data[data.length -1] = null;
var newStack = Arrays.copyOf(data,data.length);
data = newStack;
}
private void growRedo() {
var newStack = Arrays.copyOf(redo,redo.length+1);
redo = newStack;
}
private void shrinkRedo() {
redo[redo.length -1] = null;
var newStack = Arrays.copyOf(redo,redo.length -1);
redo = newStack;
}
@Override
public boolean redo() {
// TODO Auto-generated method stub
return false;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
@Override
public void concatenateStack(ArrayStack stack) {
// TODO Auto-generated method stub
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply