熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> ASP編程 >> 正文

用C#的類實現數據結構的堆棧算法

2022-06-13   來源: ASP編程 

  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;
  }
  }
  }

From:http://tw.wingwit.com/Article/program/ASP/201311/21883.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.