⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.cs

📁 北大青鸟内部资料
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -