您现在的位置是:首页
>
数据结构顺序查找算法 用C#的类实现数据结构的堆栈算法
用C#的类实现数据结构的堆栈算法 u i g Sy tem ame ace DataStructure { /// lt ummary gt /// Cla 的摘要说明 ///
用C#的类实现数据结构的堆栈算法

using System; namespace DataStructure { /// <summary> /// Class 的摘要说明 /// </summary> public class Stack//栈类 { private int count= ; private Node first=null;//定义首结点 public bool Empty { get { return(first==null); } } public int Count { get { return count; } } public object Pop()//入栈 { if(first==null) { throw new InvalidOperationException( Can not 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++; } public Stack() { // // TODO: 在此处添加构造函数逻辑 // } } 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; } } } lishixinzhi/Article/program/ASP/201311/21883
很赞哦! (1030)