




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、棧的先進后出的算法演示程序樓主ysycrazy(風中狂2006-03-29 15:08:25 在Java / J2SE / 基礎(chǔ)類提問/*棧的先進后出的算法演示程序,請各位大俠指教。*/public class ThreadTestpublic static void main(String args/從命令行參數(shù)中獲得該棧的大小MyStack st = new MyStack(new Integer(Value(; new Thread(new Producer(st.start(;new Thread(new Customer(st.start(;class MyStac
2、k /棧char data ;private int index = 0;private boolean bFull = false;public MyStack(int sizedata = new charsize;public synchronized void pushData(char c /往棧中推數(shù)據(jù)if (bFulltrythis.wait(;catch(Exception e;dataindex=c;tryThread.sleep(300;catch(InterruptedException ieie.printStackTrace(;index+;if (index = d
3、ata.lengthbFull = true;if (bFullthis.notify(;public synchronized char popData( /從棧中取數(shù)據(jù)if (!bFulltrythis.wait(;catch(Exception ee.printStackTrace(;char c;index-;tryThread.sleep(300;catch(InterruptedException ieie.printStackTrace(;c=dataindex;if (index=0bFull = false;if (!bFullthis.notify(;return c;cl
4、ass Producer implements RunnableMyStack st;public Producer(MyStack stthis.st=st;public void run(while (truest.pushData(char(Math.random( * 26 + 'A'class Customer implements RunnableMyStack st;public Customer(MyStack stthis.st=st;public void run(while (truest.popData(;JA V A堆棧問題1懸賞分:0 - 解決時間:
5、2006-9-12 10:10class Stackprivate int stck=new int10;private int tos;Stack(tos=-1;void push(int itemif(tos=9elsestck+tos=item;int pop(if(tos<0return 0;return stcktos-;class TestStackpublic static void main(String argsStack mystack1 = new Stack(;Stack mystack2 = new Stack(;for(int i=0;i<10;i+mystack1.push(i;for(int i=10;i<20;i+mystack2.push(i;for(int i=0;i<10;i+for(int i=0;i<10;i+前面方法里壓棧只寫到9,而后面都出來10到20,為什么還可以提問者:騰睿- 助理二級最佳答案因為測試程序構(gòu)造了
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 交通出行行業(yè)智能交通系統(tǒng)建設(shè)與管理方案
- 員工保密協(xié)議合同
- 礦權(quán)轉(zhuǎn)讓居間合同
- 房產(chǎn)出售委托協(xié)議書
- 旅游服務合作協(xié)議
- 公路工程投資合伙協(xié)議
- 人教版五年級下冊數(shù)學求最大公因數(shù)練習300題及答案
- 鐵肩中學門衛(wèi)合同8篇
- 第1課 殖民地人民的反抗斗爭(教學設(shè)計) 九年級歷史下冊同步高效課堂(部編版)
- 第十章 第4節(jié) 跨學科實踐:制作微型密度計(教學設(shè)計)2024-2025學年度人教版(2024)物理八年級下冊
- 2024年部編版九年級語文上冊電子課本(高清版)
- 探究“雙高”背景下高職數(shù)學與專業(yè)融合創(chuàng)新能力培養(yǎng)教學模式
- 廣東省高等教育“創(chuàng)新強校工程”考核指標及評分辦法
- 外研版小學五年級上冊英語閱讀理解專項習題
- 高中二年級下學期數(shù)學《導數(shù)在不等式恒成立問題中的應用》課件
- 儲能項目工具【Excel計算表】用戶側(cè)儲能電站投資收益分析表(修正版)
- 汽車駕駛員高級工題庫與答案
- 《網(wǎng)絡安全防護項目教程》課件項目4 數(shù)據(jù)庫安全防護
- 2023年血液安全技術(shù)核查指南(醫(yī)療機構(gòu))
- 手術(shù)室標本管理及送檢評分標準
- 幫朋友貸款免責協(xié)議書范本
評論
0/150
提交評論