stack.cs
来自「北大青鸟-Cs学生用书-教师用书实例源代码.rar」· CS 代码 · 共 66 行
CS
66 行
using System;
namespace StackSample
{
public class Stack
{
private Node first = null;
private int count = 0;
public bool Empty
{
get
{
return (first == null);
}
}
public int Count
{
get
{
return count;
}
}
public object Pop()
{
if (first == null)
{
throw new InvalidOperationException ("不能从空堆栈进行Pop操作");
}
else
{
object temp = first.Value;
first = first.Next;
count --;
return temp;
}
}
public void Push(object o)
{
first = new Node(o, first);
count++;
}
private 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;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?