会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
tallman
C#实现队列
using
System;
namespace
QueueWithCSharp
{
/**/
///
<summary>
///
LinkList 的摘要说明。
///
</summary>
///
public
class
Node
{
public
int
data;
public
Node prior, next;
public
Node()
{
prior
=
null
;
next
=
null
;
data
=
0
;
}
}
public
class
Queue
{
Node head, rear;
int
length;
public
int
Length
{
get
{
return
length;
}
}
public
Queue()
{
//
//
TODO: 在此处添加构造函数逻辑
//
head
=
rear
=
null
;
length
=
0
;
}
public
void
EnQueue(
int
data)
//
追加
{
if
(rear
==
null
)
{
rear
=
new
Node();
head
=
rear;
rear.data
=
data;
length
++
;
}
else
{
rear.next
=
new
Node();
rear.next.data
=
data;
length
++
;
rear
=
rear.next;
}
}
public
int
DeQueue()
{
if
(length
<=
0
)
{
rear
=
head
=
null
;
Console.WriteLine(
"
队列中没有元素
"
);
return
0
;
}
int
data
=
head.data;
head
=
head.next;
length
--
;
return
data;
}
public
void
Print()
{
string
str
=
""
;
Node current
=
head;
while
(current
!=
null
)
{
if
(current
==
head)
{
str
+=
current.data.ToString();
}
else
{
str
+=
"
<-
"
+
current.data.ToString();
}
current
=
current.next;
}
//
end while current
Console.WriteLine(str);
}
}
}
posted on
2007-10-21 15:18
BugHunter
阅读(
325
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告