zoukankan      html  css  js  c++  java
  • Algs4-1.3链表实现不定容泛型Stack不支持迭代

     public class Stack<Item>
    {
        private int N;
        private Node first;
        private class Node
        {
            Item item;
            Node next;
        }
        public boolean isEmpty()
        {return N==0;}
       
        public int size()
        {return N;}
       
        public void push(Item item)
        {
            Node oldfirst=first;
            first=new Node();
            first.item=item;
            first.next=oldfirst;
            N++;
        }
       
        public Item pop()
        {
            Item item=first.item;
            first=first.next;
            N--;
            return item;
        }
       
        public static void main(String[] args)
        {
            Stack<String> s=new Stack<String>();
            while(!StdIn.isEmpty())
            {
                String item=StdIn.readString();
                if(!item.equals("-"))
                    s.push(item);
                else if(!s.isEmpty())
                    StdOut.print(s.pop()+" ");
            }//end while
            StdOut.println("(" +s.size()+" left on stack)");
        }
    }
  • 相关阅读:
    Java学习(零)
    WP7 Toolkit ExpanderView 控件 介绍 01
    WP7 Tip:改变启动页
    WP7 Toolkit LoopingSelector 控件 介绍
    azkaban hdfs plugin 配置
    修改hostname
    hybris Models
    hadoop 2.6 安装配置
    hadoop CDH5.1.0 配置kerberos
    flumengtaildirectorysource 修改调试可用
  • 原文地址:https://www.cnblogs.com/longjin2018/p/9849264.html
Copyright © 2011-2022 走看看