如下所示:
packagecom.learn.algorithm.linkStack; /** * 链栈实现 * @author Jiekun.Cui * @param*/ publicclassLinkStack { privateLinkStack .Node top =newNode (); privateintsize=0; /** * 进栈 * @param t * @return ; */ publicbooleanpush(T t){ if( isEmpty() ) { top.next =newNode (t); }else{ Node newNode =newNode (t, top.next); top.next = newNode; } size ++ ; returntrue; } /** * 出栈 * @param t * @return */ publicT pop(){ if( isEmpty() ) { returnnull; }else{ LinkStack .Node node = top.next; top.next = node.next; size --; returnnode.getT(); } } /** * 获取栈顶元素 * @return */ publicT getTop(){ if( isEmpty() ) { returnnull; }else{ returntop.next.getT(); } } /** * 判断栈是不是为空 * @return */ publicbooleanisEmpty(){ returnsize() ==0; } /** * 返回栈的大小 * @return */ publicintsize(){ returnsize; } /** * @author 链栈的节点类 * @param */ classNode { privateT t =null; privateNode next =null; publicNode(){ } publicNode(T t){ this.t = t; } publicNode(T t,Node next){ this.t = t; this.next =next; } publicT getT() { returnt; } publicvoidsetT(T t) { this.t = t; } publicNode getNext() { returnnext; } publicvoidsetNext(Node next) { this.next = next; } } }
package com.learn.algorithm.linkStack; /** * 链栈测试 * @author Jiekun.Cui */ public class Demo { public static void main(String[] args) { LinkStackls = new LinkStack<>(); ls.push(1); ls.push(2); ls.pop(); ls.push(4); ls.push(5); ls.push(6); while ( !ls.isEmpty() ) { System.out.println(ls.pop()); } } }
恋爱进行时九游版
恋爱进行时九游版是一款以模拟恋爱玩法为核心的角色扮演手游,精
皇室对决fr(Null’s Royale)
皇室对决fr,即皇室战争的私服变态版本,在该版本中玩家能够拥
养了个猫联机版游戏
养了个猫小游戏一个猫咪主题的模拟经营类型的手游,在游戏中我那
模拟山羊收获日小米版
模拟山羊收获日小米版是一个极其魔性的手机游戏,在游戏中玩家将
女配逆袭之素衣
女配逆袭之素衣是一款恋爱养成冒险的一款游戏,可以角色扮演,在