2015-04-08 41 views
-3

我想使用堆栈向后打印单向链表的数据,但是卡住了。 Stack类如下:使用堆栈向后打印单向链表的数据

public class Stack{ 

    public boolean isEmpty(){};  
    public void push(int n){};  
    public int peek(){}; 
    public int pop(){}; 

} 

public class node{ 
    int data; 
    node next; 

} 

public class list{  
    node first;  
} 

回答

0
Stack<String> stack = new Stack<String>(); 
    List<String> list = new ArrayList<String>(); 

    list.add("a"); 
    list.add("b"); 
    list.add("c"); 

    for (String s: list){ 
     stack.push(s); 
    } 

    while (!stack.isEmpty()){ 
     System.out.println(stack.pop()); 
    }