Дек на C#


#1

Помогите пожалуйста реализовать дек на C#


#2

Дек на английском будет, вроде как, Deq.

вот код:

class Deq<T>
{
    T[] array;
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> Deq<span class="br0" style="color: green;">(</span><span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
    array <span class="sy0" style="color: green;">=</span> <span class="kw3" style="color: green;">new</span> T<span class="br0" style="color: green;">[</span><span class="nu0" style="color: #ff0000;">0</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> <span class="kw4" style="color: #6666cc; font-weight: bold;">int</span> Count
<span class="br0" style="color: green;">{</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">get</span>
    <span class="br0" style="color: green;">{</span>
        <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span><span class="sy0" style="color: green;">;</span>
    <span class="br0" style="color: green;">}</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> <span class="kw4" style="color: #6666cc; font-weight: bold;">bool</span> Empty
<span class="br0" style="color: green;">{</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">get</span>
    <span class="br0" style="color: green;">{</span>
        <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">></span> <span class="nu0" style="color: #ff0000;">0</span><span class="sy0" style="color: green;">;</span>
    <span class="br0" style="color: green;">}</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> <span class="kw4" style="color: #6666cc; font-weight: bold;">void</span> PushBack<span class="br0" style="color: green;">(</span>T item<span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
    Array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Resize</span><span class="br0" style="color: green;">(</span><span class="kw1" style="color: #0600ff; font-weight: bold;">ref</span> array, array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;"> </span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">)</span><span class="sy0" style="color: green;">;</span>
    array<span class="br0" style="color: green;">[</span>array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">]</span> <span class="sy0" style="color: green;">=</span> item<span class="sy0" style="color: green;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> <span class="kw4" style="color: #6666cc; font-weight: bold;">void</span> PushFront<span class="br0" style="color: green;">(</span>T item<span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
    Array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Resize</span><span class="br0" style="color: green;">(</span><span class="kw1" style="color: #0600ff; font-weight: bold;">ref</span> array, array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;"> </span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">)</span><span class="sy0" style="color: green;">;</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">for</span> <span class="br0" style="color: green;">(</span><span class="kw4" style="color: #6666cc; font-weight: bold;">int</span> i <span class="sy0" style="color: green;">=</span> array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="sy0" style="color: green;">;</span> i <span class="sy0" style="color: green;">></span> <span class="nu0" style="color: #ff0000;">0</span><span class="sy0" style="color: green;">;</span> i<span class="sy0" style="color: green;">--</span><span class="br0" style="color: green;">)</span>
        array<span class="br0" style="color: green;">[</span>i<span class="br0" style="color: green;">]</span> <span class="sy0" style="color: green;">=</span> array<span class="br0" style="color: green;">[</span>i <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    array<span class="br0" style="color: green;">[</span><span class="nu0" style="color: #ff0000;">0</span><span class="br0" style="color: green;">]</span> <span class="sy0" style="color: green;">=</span> item<span class="sy0" style="color: green;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> T PopBack<span class="br0" style="color: green;">(</span><span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
    T item <span class="sy0" style="color: green;">=</span> array<span class="br0" style="color: green;">[</span>array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    Array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Resize</span><span class="br0" style="color: green;">(</span><span class="kw1" style="color: #0600ff; font-weight: bold;">ref</span> array, array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">)</span><span class="sy0" style="color: green;">;</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> item<span class="sy0" style="color: green;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> T PopFront<span class="br0" style="color: green;">(</span><span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
    T item <span class="sy0" style="color: green;">=</span> array<span class="br0" style="color: green;">[</span><span class="nu0" style="color: #ff0000;">0</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">for</span> <span class="br0" style="color: green;">(</span><span class="kw4" style="color: #6666cc; font-weight: bold;">int</span> i <span class="sy0" style="color: green;">=</span> <span class="nu0" style="color: #ff0000;">0</span><span class="sy0" style="color: green;">;</span> i <span class="sy0" style="color: green;"><</span> array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="sy0" style="color: green;">;</span> i<span class="sy0" style="color: green;">  </span><span class="br0" style="color: green;">)</span>
        array<span class="br0" style="color: green;">[</span>i<span class="br0" style="color: green;">]</span> <span class="sy0" style="color: green;">=</span> array<span class="br0" style="color: green;">[</span>i <span class="sy0" style="color: green;"> </span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    Array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Resize</span><span class="br0" style="color: green;">(</span><span class="kw1" style="color: #0600ff; font-weight: bold;">ref</span> array, array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">)</span><span class="sy0" style="color: green;">;</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> item<span class="sy0" style="color: green;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> T Front
<span class="br0" style="color: green;">{</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">get</span>
    <span class="br0" style="color: green;">{</span>
        <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> array<span class="br0" style="color: green;">[</span><span class="nu0" style="color: #ff0000;">0</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    <span class="br0" style="color: green;">}</span>
<span class="br0" style="color: green;">}</span>
<span class="kw1" style="color: #0600ff; font-weight: bold;">public</span> T Back
<span class="br0" style="color: green;">{</span>
    <span class="kw1" style="color: #0600ff; font-weight: bold;">get</span>
    <span class="br0" style="color: green;">{</span>
        <span class="kw1" style="color: #0600ff; font-weight: bold;">return</span> array<span class="br0" style="color: green;">[</span>array<span class="sy0" style="color: green;">.</span><span class="me1" style="color: #0000ff;">Length</span> <span class="sy0" style="color: green;">-</span> <span class="nu0" style="color: #ff0000;">1</span><span class="br0" style="color: green;">]</span><span class="sy0" style="color: green;">;</span>
    <span class="br0" style="color: green;">}</span>
<span class="br0" style="color: green;">}</span>

}