标签:
1 package cn.it.struct; 2 3 public class MyStack<T> { 4 private int top=-1; 5 6 private Node<T> current; 7 8 9 private class Node<T>{ 10 private T data; 11 12 private Node<T> next; 13 14 private Node<T> pre; 15 16 } 17 18 //初始化 19 public MyStack(){ 20 top = -1; 21 current = new Node<T>(); 22 } 23 24 //压Stack 25 public boolean push(T data){ 26 Node<T> node = new Node<T>(); 27 node.data = data; 28 current.next = node; 29 current = node.pre; 30 current = node; 31 top++; 32 return false; 33 } 34 35 //出Stack 36 public T poll(){ 37 T data = current.data; 38 current = current.pre; 39 top--; 40 return data; 41 } 42 }
标签:
原文地址:http://www.cnblogs.com/mozhuhao/p/4483811.html