I have one array (25*ax+c-d/2) and i want to put everything in a stack and next remove the operators ( *;+;-;/) and have at the end (25;ax;c;d) in a stack implementation.
Right now i have :
import java.util.*;
public class StackDemo {
public static void main(String args[])
{
//Creating array
ArrayList<String> al = new ArrayList<String>();
//Adding to array
al.add("25*ax+c-d/2");
//Creating a stack
Stack<String> STACK = new Stack<String>();
//Adding array to stack
for(String str : al)
STACK.add(str);
// Displaying the Stack
System.out.println("Initial Stack: " + STACK);
}
}
I know I'm grouping everything in the same stack position, but how can I separate and then remove the operators?
25) or an operator (e.g.+or-). Then, your code needs to read each token, one at a time, and figure out what to do with them, by putting them on the stack, or doing a math operation.