Java链栈

package com.lxm.customDataStructure;

public class LinkStack<T>{
class Node<T>{
T data;
Node next;
Node(T data)
{
this.data=data;
this.next = null;
}
} Node<T> head; public LinkStack(T data)
{
this.head = null;
} public boolean isEmpty()
{
return this.head==null;
} public void push(T e)
{
Node temp = new Node(e);
temp.next = this.head;
this.head = temp;
} public T pop()
{
if(this.isEmpty()) return null;
Node temp = this.head;
this.head = temp.next;
return (T) temp.data;
} public static void main(String[] args)
{
LinkStack<Integer> S = new LinkStack<Integer>(0);
for(int i=0;i<10;i++)
{
S.push(i+1);
} while(S.isEmpty()==false)
{
System.out.print(S.pop()+"\t");
}
System.out.println();
}
}
上一篇:jq优化


下一篇:gulpfile.js文档