import java.util.*;
class Test1{
public static void main(String[] args) throws Exception{
Stack<String> stack = new Stack<String>();
String[] s ={"<","blue",">","<","red",">","H","<","/","red",">","<","/","blue",">"};
for(int i=0;i<s.length;i++){
if(s[i].equals("<")&&!s[i+1].equals("/")){
System.out.println("pushed: "+ stack.push(s[i+1]));
if(s[i].equals(">")&&!s[i+1].equals("<")){
System.out.println(" - "+s[i+1]);
} else{
System.out.println();
}
}else {
if(s[i].equals("/")&&!s[i+1].equals(stack.peek())){
System.out.println("error");
}else{
System.out.println("pop " + stack.pop());
}
}
}
}
}
Wanted output should be:
pushed:blue
pushed:red
-H
pop: red
pop: red
Somehow I can not get such order, any suggestions please????????????????
