2010-10-20 51 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的混合:

  • 鏈接的數組列表。