会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
爬——在我爬过的每一段路上留下我的痕迹
让我永远在你的心里笑 □□□□
导航
博客园
首页
新随笔
联系
订阅
管理
公告
内存管理
using
System;
public
class
Stack
{
private
Node first
=
null
;
public
bool
Empty
{
get
{
return
(first
==
null
);
}
}
public
object
Pop()
{
if
(first
==
null
)
throw
new
Exception(
"
Can't Pop from an empty Stack.
"
);
else
{
object
temp
=
first.Value;
first
=
first.Next;
return
temp;
}
}
public
void
Push(
object
o)
{
first
=
new
Node(o,first);
}
}
class
Node
{
public
Node Next;
public
object
Value;
public
Node(
object
value) :
this
(value,
null
)
{}
public
Node(
object
value , Node next)
{
Next
=
next;
Value
=
value;
}
}
class
Text
{
static
void
Main()
{
Stack s
=
new
Stack();
for
(
int
i
=
0
; i
<
10
; i
++
)
s.Push(i);
while
(
!
s.Empty)
Console.WriteLine(s.Pop());
}
}
posted on
2006-05-18 18:34
张志
阅读(
490
) 评论(
0
)
收藏
举报
刷新页面
返回顶部