今天开博了2007-7-16

开博没有太监的客。。。

 

c#数据结构———栈

栈是栈是受约束的链表,栈是一种后进先(LIFO)出的数据结构。

using System;

using LinkedListLibrary;

//栈是受约束的链表

//栈底结点的链接成员社为null

namespace StackInheritanceLibrary

{

     public class StackInheritance:List

     {

         public StackInheritance():base("stack")

         {

         }

         public void Push(object dataValue)//压栈

         {

              InsertAtFront(dataValue);

         }

         public object Pop()//出栈

         {

              return RemoveFromFront();

         }

     }

}

第二种实现方法

using System;

using LinkedListLibrary;

 

//通过合成来重用List

namespace StackCompositionLibrary

{

     public class StackComposition:List

     {

         public List stack;

         public StackComposition()

         {

              stack = new List("stack");

         }

         public void Push(object dataValue)

         {

              stack.InsertAtFront(dataValue);

         }

         public object Pop()

         {

              return stack.RemoveFromFront();

         }

         public bool IsEmpty()

         {

              return stack.IsEmpty();

         }

         public void Print()

         {

              stack.Print();

         }

     }

}

队列实现

using System;

using LinkedListLibrary;

namespace QueueInheritanceLibrary

{

     public class QueueInheritance:List

     {

         public QueueInheritance():base("queue")

         {

         }

         public void Enqueue(object dataValue)

         {

              InsertAtBack(dataValue);

         }

         public object Dequeue()

         {

              return RemoveFromFront();

         }

     }

}

 

posted on 2005-04-25 21:55  胡敏  阅读(2208)  评论(6)    收藏  举报

导航