| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 713 人关注过本帖
标题:stack的实现
取消只看楼主 加入收藏
chianti
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2005-5-1
收藏
 问题点数:0 回复次数:2 
stack的实现

请指正有不足的地方 import java.util.*; import java.io.*; class stack1 { public static void main(String args[]) { operate he=new operate(); int k;int y=1; DataInputStream ha1=new DataInputStream(System.in); while(y!=0) {try {he.menu(); k=Integer.parseInt(ha1.readLine()); switch(k) {case 1 :{he.enter();break;} case 2 : {he.remove();break;} case 3 : {he.display();break;} case 4 : {he.clear();break;} case 5 : {y--;break;} default :break; } } catch (Exception e) {System.out.println("---input error,please input

right order");} } } } class operate { ArrayList al=new ArrayList(); void menu() {System.out.println("-----menu of the program"); System.out.println("1).enter the value in the

stack"); System.out.println("2).remove the last value from

the stack"); System.out.println("3).display the value"); System.out.println("4).clear all the value"); System.out.println("5).exit"); System.out.print("I choose:"); } void enter() {int y=1,k; DataInputStream ha2=new DataInputStream(System.in); while(y!=0) { try { System.out.print("enter you number :"); int i; i=Integer.parseInt(ha2.readLine()); al.add(new Integer(i)); y--; System.out.println("--type 1 to enter more"); k=Integer.parseInt(ha2.readLine()); if(k==1) y++; } catch (Exception e) {} } } void remove() { int i,y=1,k; i=al.size(); if(i!=0) { DataInputStream ha3=new DataInputStream(System.in); while(y!=0) {try {al.remove(i-1); i=i-1; System.out.println("--type 1 to remove more"); k=Integer.parseInt(ha3.readLine()); if(k==1) y++; } catch (Exception e) {} } } else System.out.println("--null"); } void display() { int i; i=al.size(); if(i!=0) System.out.println(al); else System.out.println("--null"); } void clear() { al.clear();} }

搜索更多相关主题的帖子: stack 
2005-05-14 10:41
chianti
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2005-5-1
收藏
得分:0 
void remove()
        { int i,y=1,k;
         i=al.size();
         if(i!=0)   {
            DataInputStream ha3=new DataInputStream(System.in);
             while(y!=0)
              {try
                {al.remove(i-1);
                 i=i-1;
                 y=y-1;//写错的地方,前面的少了一个y--;sorry
                 System.out.println("--type 1 to remove more");
                 k=Integer.parseInt(ha3.readLine());
                 if(k==1) y++;
                }
               catch (Exception e)
                {}
              }         
                     }
          else System.out.println("--null");
        }
2005-05-15 11:08
chianti
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2005-5-1
收藏
得分:0 
斑竹:
我是练习呀,我也是这个学期才开的课
2005-05-15 11:10
快速回复:stack的实现
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015972 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved