using System;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
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();
}
}
}