隨筆:20 文章:1 評論:8 引用:0
╰⊙д⊙╯。oо○
面朝大海·春暖花開
BlogJava
首頁
發(fā)新隨筆
發(fā)新文章
聯(lián)系
聚合
管理
『第四章』隊列的基本使用
//
Queue.java
//
demonstrates queue
//
to run this program: C>java QueueApp
////////////////////////////////////////////////////////////////
class
Queue
{
private
int
maxSize;
private
long
[] queArray;
private
int
front;
private
int
rear;
private
int
nItems;
//
--------------------------------------------------------------
public
Queue(
int
s)
//
constructor
{
maxSize
=
s;
queArray
=
new
long
[maxSize];
front
=
0
;
rear
=
-
1
;
nItems
=
0
;
}
//
--------------------------------------------------------------
public
void
insert(
long
j)
//
put item at rear of queue
{
if
(rear
==
maxSize
-
1
)
//
deal with wraparound
rear
=
-
1
;
queArray[
++
rear]
=
j;
//
increment rear and insert
nItems
++
;
//
one more item
}
//
--------------------------------------------------------------
public
long
remove()
//
take item from front of queue
{
long
temp
=
queArray[front
++
];
//
get value and incr front
if
(front
==
maxSize)
//
deal with wraparound
front
=
0
;
nItems
--
;
//
one less item
return
temp;
}
//
--------------------------------------------------------------
public
long
peekFront()
//
peek at front of queue
{
return
queArray[front];
}
//
--------------------------------------------------------------
public
boolean
isEmpty()
//
true if queue is empty
{
return
(nItems
==
0
);
}
//
--------------------------------------------------------------
public
boolean
isFull()
//
true if queue is full
{
return
(nItems
==
maxSize);
}
//
--------------------------------------------------------------
public
int
size()
//
number of items in queue
{
return
nItems;
}
//
--------------------------------------------------------------
}
//
end class Queue
////////////////////////////////////////////////////////////////
class
QueueApp
{
public
static
void
main(String[] args)
{
Queue theQueue
=
new
Queue(
5
);
//
queue holds 5 items
theQueue.insert(
10
);
//
insert 4 items
theQueue.insert(
20
);
theQueue.insert(
30
);
theQueue.insert(
40
);
theQueue.remove();
//
remove 3 items
theQueue.remove();
//
(10, 20, 30)
theQueue.remove();
theQueue.insert(
50
);
//
insert 4 more items
theQueue.insert(
60
);
//
(wraps around)
theQueue.insert(
70
);
theQueue.insert(
80
);
while
(
!
theQueue.isEmpty() )
//
remove and display
{
//
all items
long
n
=
theQueue.remove();
//
(40, 50, 60, 70, 80)
System.out.print(n);
System.out.print(
"
"
);
}
System.out.println(
""
);
}
//
end main()
}
//
end class QueueApp
////////////////////////////////////////////////////////////////
發(fā)表于 2008-04-26 11:20
dreamingnest
閱讀(194)
評論(0)
編輯
收藏
所屬分類:
鏈表和棧(結(jié))
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
『第四章』后綴表達(dá)式求值
『第四章』中綴表達(dá)式轉(zhuǎn)換成后綴表達(dá)式
『第四章』優(yōu)先級隊列
『第四章』隊列的基本使用
『第四章』棧的使用
『第三章』幾種排序的關(guān)鍵代碼
『第二章』二分查找
CALENDER
<
2008年4月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的文章
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
(13)
應(yīng)用程序(4)
(rss)
數(shù)據(jù)結(jié)構(gòu)(java)
(rss)
算法程序總結(jié)(2)
(rss)
鏈表和棧(結(jié))(7)
(rss)
隨筆檔案
(21)
2008年10月 (1)
2008年5月 (7)
2008年4月 (13)
外面的世界
懶散狂徒的專欄(天行健,君子以自強(qiáng)不息 地勢坤,君子以厚德載物)
(rss)
這里的朋友
保爾任(思想比知識更重要 成長比成功更重要)
搜索
最新評論
1.?re: BFS和DFS兩種方法獲取指定目錄下的所有目錄和文件
學(xué)習(xí)了
--fejay
2.?re: 關(guān)于螞蟻問題(Ants)
實際過程可以這么進(jìn)行抽象模擬:
序列中的元素帶有方向,進(jìn)行負(fù)值部分移動到負(fù)值區(qū)域,正值部分移動到正值區(qū)域時就不再發(fā)生碰撞,此時絕對值最小的值決定剩余爬行時間
--zdh
3.?re: 關(guān)于螞蟻問題(Ants)
這個問題看到實質(zhì)就很簡單,所有的螞蟻都是相同的螞蟻,因此可以看成所有的螞蟻都可以穿過對面爬過來的螞蟻就ok啦,最長時間就是兩端的螞蟻向另一端爬出去,最短的就是兩端的四個螞蟻向所在端爬出:)
--zdh
4.?re: 關(guān)于螞蟻問題(Ants)
評論內(nèi)容較長,點擊標(biāo)題查看
--blues
5.?re: 關(guān)于螞蟻問題(Ants)
評論內(nèi)容較長,點擊標(biāo)題查看
--dreamingnest
閱讀排行榜
1.?關(guān)于螞蟻問題(Ants)(2242)
2.?通過排序總結(jié)java泛型數(shù)組列表(1649)
3.?堆棧解(非遞歸)決迷宮問題(1414)
4.?ACM中使用JAVA的介紹(1048)
5.?~·掃雷小游戲·~(1035)
評論排行榜
1.?關(guān)于螞蟻問題(Ants)(7)
2.?BFS和DFS兩種方法獲取指定目錄下的所有目錄和文件(1)
3.?一著名軟件公司的java筆試算法題的答案 (0)
4.?堆棧解(非遞歸)決迷宮問題(0)
5.?堆排序代碼(0)
Powered By:
博客園
模板提供
:
滬江博客
主站蜘蛛池模板:
亚洲Av无码国产情品久久
|
久久伊人久久亚洲综合
|
中国一级特黄高清免费的大片中国一级黄色片
|
国产传媒在线观看视频免费观看
|
九九九国产精品成人免费视频
|
亚洲国产精彩中文乱码AV
|
野花高清在线电影观看免费视频
|
亚洲熟妇av午夜无码不卡
|
亚洲男人的天堂一区二区
|
91福利免费视频
|
在线观看免费亚洲
|
久久精品国产亚洲夜色AV网站
|
大地资源免费更新在线播放
|
香蕉免费看一区二区三区
|
亚洲一区二区影视
|
中文字幕在线亚洲精品
|
成全影视免费观看大全二
|
天黑黑影院在线观看视频高清免费
|
亚洲人成777在线播放
|
中文字幕亚洲乱码熟女一区二区
|
免费看片在线观看
|
在线观看人成视频免费无遮挡
|
亚洲日日做天天做日日谢
|
亚洲国产精品va在线播放
|
亚洲一卡二卡三卡
|
亚洲三区在线观看无套内射
|
成人毛片18岁女人毛片免费看
|
a级午夜毛片免费一区二区
|
亚洲熟妇av午夜无码不卡
|
久久亚洲美女精品国产精品
|
免费国产综合视频在线看
|
成人免费视频观看无遮挡
|
久久午夜无码免费
|
一级免费黄色毛片
|
日韩精品亚洲专区在线影视
|
亚洲性猛交xx乱
|
亚洲视频在线观看一区
|
国产亚洲精品成人AA片新蒲金
|
国产精品无码一区二区三区免费
|
亚洲欧洲日本在线观看
|
久久久久亚洲精品无码系列
|