Here's the problem... I want to create a table about the stack like this:

((A+B)-C)
Symbol    Postfix      Stack
(                       ( 
(                       ((                       
A           A           ((                       
+           A           ((+
B           AB          ((+
)           AB+         (
-           AB+         (-
C           AB+C        (-
)           AB+C-

But i don't know how to read the input from the user... (The Characters)
Example ((A+B)-C) : I want to get the '(' and the rest

//An incomplete code
//---------------------------------------------------------------------------------------

import java.util.*;

public class Stack2<Item> implements Iterable<Item> {
	
	Scanner kbd = new Scanner(System.in);
	
	private int N;          
    private Node first;    
    
    private class Node {
        private Item item;
        private Node next;
    }

    public Stack2() {
    	first = null;
        N = 0;
    }
    
    public boolean isEmpty() {
    	return first == null;
    }
    
    public int size(){
    	return N; 
    }
    
     public Item peek() {
        return first.item;
    }
    
    public void push(Item item) {
        Node oldfirst = first;
        first = new Node();
        first.item = item;
        first.next = oldfirst;
        N++;
    }
    
    public Item pop() {
        if (isEmpty()) throw new RuntimeException("Stack underflow");
        Item item = first.item;        
        first = first.next;            
        N--;
        return item;                   
    }
    
    public Iterator<Item> iterator()  { 
      	return new StackIterator();  
    }
    
    private class StackIterator implements Iterator<Item> {
        private Node current = first;
        public boolean hasNext()  {
        	return current != null;                  
        }
        
        public void remove() {
        	 throw new UnsupportedOperationException();
        }

        public Item next() {
            if (!hasNext()) throw new NoSuchElementException();
            Item item = current.item;
            current = current.next; 
            return item;
        }
    } 
    
    public static void main(String[] args){
    	
       	Stack<String> stack = new Stack<String>();
       	
       	
    }			
    
    
}

The Table was Disarranged!

Please mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.