Decode360's Blog

          業精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 ::  :: 管理 ::
            302 隨筆 :: 26 文章 :: 82 評論 :: 0 Trackbacks
          Class Stack<E>
          						java.lang.Object
          						extended by 
          						java.util.AbstractCollection<E>
                extended by java.util.AbstractList<E>
                    extended by java.util.Vector<E>
                        extended by java.util.Stack<E>
          ?
          Method Summary
          ?boolean empty ()
          ??????????Tests if this stack is empty.
          ? E peek ()
          ??????????Looks at the object at the top of this stack without removing it from the stack.
          ? E pop ()
          ??????????Removes the object at the top of this stack and returns that object as the value of this function.
          ? E push ( E ?item)
          ??????????Pushes an item onto the top of this stack.
          ?int search ( Object?o)
          ??????????Returns the 1-based position where an object is on this stack.
          ?
          ?
          ?
          另外還繼承了java.util.Vector<E>中的基本方法,常見的用法如下所示:
          ?
          ?
          import java.util.*;
          ?
          public class kkk{
          ?public static void main(String args[]){
          ??int m = 1;
          ??Stack<Integer> a = new Stack<Integer>();
          ??
          ??a.push(m);?? //壓入1
          ??a.push(m+1); //壓入2
          ??a.push(m+2); //壓入3
          ??a.push(m+3); //壓入4
          ??a.push(m+4); //壓入5
          ??? System.out.println(a.push(m+5)); //壓入6,并返回當前值
          ?
          ??? System.out.println(a.empty());?? //判斷棧是否為空,為空則TRUE
          ??? System.out.println(a.isEmpty()); //判斷棧是否為空,為空則TRUE
          ???
          ??System.out.println(a.size());???? //返回當前棧長度
          ??System.out.println(a.toString()); //返回當前棧的內容
          ??
          ??System.out.println(a.lastElement());? //返回當前棧中的最后一個元素6
          ??System.out.println(a.firstElement()); //返回當前棧中的第一個元素1
          ??
          ??System.out.println(a.peek()); //返回當前值6
          ??System.out.println(a.pop());? //返回當前值并壓出6
          ??System.out.println(a.pop());? //返回當前值并壓出5
          ??
          ??System.out.println(a.search(3));
          ??//搜索“3”在棧中出現的位置,頂端為1,其余依次累加,若有多個則返回第1個的位置
          ?
          ??a.add(m+9); //壓入10,跟push一樣的效果
          ??a.clear(); //清空棧
          ??
          ??? System.out.println(a.empty());?? //判斷棧是否為空,為空則TRUE
          ??? System.out.println(a.isEmpty()); //判斷棧是否為空,為空則TRUE?
          ?
          ?}
          }
          ?
          ?
          ?




          -The End-

          posted on 2008-12-01 22:42 decode360-3 閱讀(344) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 鄂州市| 蓝山县| 新邵县| 彰武县| 新建县| 淮南市| 金塔县| 博客| 崇义县| 丽江市| 勃利县| 礼泉县| 泰顺县| 板桥市| 从江县| 星子县| 文昌市| 南郑县| 黑龙江省| 六盘水市| 北辰区| 荆门市| 鸡西市| 静安区| 陆河县| 崇州市| 左权县| 华池县| 贵港市| 崇左市| 凌海市| 辽阳县| 尼木县| 郧西县| 神池县| 樟树市| 嘉黎县| 敦煌市| 北海市| 旅游| 焦作市|