Rev 1122 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1092 | dev | 1 | using System; |
2 | using System.Collections; |
||
3 | |||
4 | namespace TCPproxy |
||
5 | { |
||
6 | public class LinkedList |
||
7 | { |
||
8 | private class ListNode |
||
9 | { |
||
10 | public object data; |
||
11 | public ListNode next; |
||
12 | } |
||
13 | |||
14 | private class LinkedEnumerator : IEnumerator |
||
15 | { |
||
16 | private LinkedList list; |
||
17 | private ListNode current; |
||
18 | |||
19 | public object Current |
||
20 | { |
||
21 | get |
||
22 | { |
||
23 | if(current == null) throw new InvalidOperationException("No current element"); |
||
24 | |||
25 | return current.data; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public bool MoveNext() |
||
30 | { |
||
31 | if(current == null) |
||
32 | { |
||
33 | current = list.first; |
||
34 | return (current != null); |
||
35 | } |
||
36 | else |
||
37 | { |
||
38 | if(current.next == null) |
||
39 | { |
||
40 | return false; |
||
41 | } |
||
42 | else |
||
43 | { |
||
44 | current = current.next; |
||
45 | return true; |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | |||
50 | public void Reset() |
||
51 | { |
||
52 | current = null; |
||
53 | } |
||
54 | |||
55 | public LinkedEnumerator(LinkedList list) |
||
56 | { |
||
57 | this.list = list; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | private ListNode first; |
||
62 | private ListNode last; |
||
63 | private int count = 0; |
||
64 | |||
65 | public int Count |
||
66 | { |
||
67 | get { return count; } |
||
68 | } |
||
69 | |||
70 | public IEnumerator GetEnumerator() |
||
71 | { |
||
72 | return new LinkedEnumerator(this); |
||
73 | } |
||
74 | |||
75 | public void Add(object obj) |
||
76 | { |
||
77 | ListNode node = new ListNode(); |
||
78 | node.data = obj; |
||
79 | |||
80 | if(last == null) |
||
81 | { |
||
82 | first = node; |
||
83 | } |
||
84 | else |
||
85 | { |
||
86 | last.next = node; |
||
87 | } |
||
88 | last = node; |
||
89 | count++; |
||
90 | } |
||
91 | } |
||
1234 | dev | 92 | |
93 | public class LinkedListReadOnly |
||
94 | { |
||
95 | private LinkedList origin; |
||
96 | |||
97 | public LinkedListReadOnly(LinkedList origin) |
||
98 | { |
||
99 | this.origin = origin; |
||
100 | } |
||
101 | |||
102 | public IEnumerator GetEnumerator() |
||
103 | { |
||
104 | return origin.GetEnumerator(); |
||
105 | } |
||
106 | } |
||
1092 | dev | 107 | } |