0,0 → 1,92 |
using System; |
using System.Collections; |
|
namespace TCPproxy |
{ |
public class LinkedList |
{ |
private class ListNode |
{ |
public object data; |
public ListNode next; |
} |
|
private class LinkedEnumerator : IEnumerator |
{ |
private LinkedList list; |
private ListNode current; |
|
public object Current |
{ |
get |
{ |
if(current == null) throw new InvalidOperationException("No current element"); |
|
return current.data; |
} |
} |
|
public bool MoveNext() |
{ |
if(current == null) |
{ |
current = list.first; |
return (current != null); |
} |
else |
{ |
if(current.next == null) |
{ |
return false; |
} |
else |
{ |
current = current.next; |
return true; |
} |
} |
} |
|
public void Reset() |
{ |
current = null; |
} |
|
public LinkedEnumerator(LinkedList list) |
{ |
this.list = list; |
} |
} |
|
private ListNode first; |
private ListNode last; |
private int count = 0; |
|
public int Count |
{ |
get { return count; } |
} |
|
public IEnumerator GetEnumerator() |
{ |
return new LinkedEnumerator(this); |
} |
|
public void Add(object obj) |
{ |
ListNode node = new ListNode(); |
node.data = obj; |
|
if(last == null) |
{ |
first = node; |
} |
else |
{ |
last.next = node; |
} |
last = node; |
count++; |
} |
} |
} |