Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > C# 堆栈实现
【标  题】:C# 堆栈实现
【关键字】:C,C#
【来  源】:网络

C# 堆栈实现

Your Ad Here namespace Stack{
using System;
public class Stack
{
private Node first = null;
private int count = 0;
/***********************************************Property Procedures do not accept any parameters. Note the
diff in the function definition (no parenthesis)************************************************/
public bool Empty
{/*******************************************Property
GetProcedure********************************************/
get
{
return (first == null);
}
}
public int Count
{/*******************************************Property Get
Procedure********************************************/
get
{ return count; } }
public object Pop()
{
if (first == null)
{
throw new InvalidOperationException ("Cant pop from an empty stack");
}
else
{
object temp = first.Value;
first = first.Next;
count--;
return temp;
}
}
public void Push(object o)
{
first = new Node(o, first);
count++;
}
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 StackTest{
static void Main()
{ Stack s = new Stack();
if (s.Empty)
Console.WriteLine("Stack is Empty");
else
Console.WriteLine("Stack is not Empty");
for (int i = 0; i < 5; i++)
s.Push(i);

Console.WriteLine("Items in Stack {0}", s.Count);

for (int i = 0; i < 5; i++)
Console.WriteLine("Popped Item is {0} and the count is {1}", s.Pop(), s.Count);
s = null;
}
}}//*********END OF CODE

//ASPHouse http://asphouse.yeah.net/

ASP+ 跟踪:【上一篇】
What's new in Microsoft SQL Server 2000(二):【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • 利用DAO访问SQL数据库
  • 妙用你的hosts文件过滤插件和广告
  • 一个自动动态播放图片的类(downmoon)
  • windows nt下使用匿名获得admin权限的几个方法
  • 解析动态联编(ZT)
  • 终端设备概述
  • <转CU坛子>
  • MySQL扫盲 -- 授权方式
  • HowTo Run OpenVPN as a non-admin user in Windows
  • Struts+Spring+Hibernate练习(完整)的续集录像教程
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.