2010-10-20 53 views

回答

0

链接列表是第三个选项。

class MyStack<T> 
{ 
    LinkedList<T> linkedList = new LinkedList<T>(); 

    public void Push(T t) 
    { 
     linkedList.AddFirst(t); 
    } 

    public T Pop() 
    { 
     T result = linkedList.First.Value; 
     linkedList.RemoveFirst(); 
     return result; 
    } 
} 

也有可能(但不是非常有用),以implement a stack using two queues

+0

链接列表是一个列表 – Woot4Moo 2010-10-20 20:45:57

+0

我现在意识到问题是用C#标记的。但是,从数据结构的角度来看,链接列表是一个列表。 – Woot4Moo 2010-10-20 20:51:48

0

我觉得只有2种可能的方式来implement a queue

  • 阵列
  • 链表

第三种方法很可能是2的混合:

  • 链接的数组列表。