c#

位置:IT落伍者 >> c# >> 浏览文章

用C#的类实现数据结构的堆栈算法


发布日期:2019年09月22日
 
用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=firstValue;

first=firstNext;

count;

return temp;

}

}

public void push(object o)//出栈

{

first=new Node(ofirst);

count++;

}

public Stack()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

}

class Node //结点类

{

public Node Next;

public object Value;

public Node(object value):this(valuenull){}

public Node(object valueNode next)

{

Next=next;

Value=value;

}

}

}

上一篇:IronPython和C#执行速度对比

下一篇:c#中dllimport报错