Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs @ 0:dec15de2c6ff
first commit
author | Kazuma |
---|---|
date | Tue, 21 Jun 2016 17:11:12 +0900 |
parents | |
children | 79da77797f7e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:dec15de2c6ff |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 using System.Collections.Generic; | |
4 using System; | |
5 | |
6 public class List<T> : System.Collections.Generic.List<T>, IEnumerable<T> { | |
7 private Node<T> head; | |
8 T[] _array; | |
9 T Count; | |
10 | |
11 | |
12 public List() { | |
13 this.head = new headNode<T>(); | |
14 } | |
15 | |
16 // この部分がだめ。safeVarargsの部分 | |
17 public List(T attributes) { | |
18 List<T> list = new List<T> (); | |
19 //for (int i = 0; i < Convert.ToInt32(attributes.Count); i++) { | |
20 list = list.addLast (attributes); | |
21 //} | |
22 this.head = list.getHead(); | |
23 } | |
24 | |
25 private List(Node<T> head) { | |
26 this.head = head; | |
27 } | |
28 | |
29 public Node<T> getHead() { | |
30 return head; | |
31 } | |
32 | |
33 public List<T> add(int num, T attribute) { | |
34 Node<T> newHead = head.add(0, num, attribute); | |
35 if (newHead == null) | |
36 return this; | |
37 return new List<T>(newHead); | |
38 } | |
39 | |
40 public List<T> addLast(T attribute) { | |
41 Node<T> newHead = head.addLast(attribute); | |
42 return new List<T>(newHead); | |
43 } | |
44 | |
45 | |
46 public T index(int num) { | |
47 int count = 0; | |
48 Node<T> currentNode = head.getNext(); | |
49 while (currentNode != null) { | |
50 if (count == num) | |
51 return currentNode.getAttribute(); | |
52 currentNode = currentNode.getNext(); | |
53 count++; | |
54 } | |
55 return default(T); | |
56 } | |
57 | |
58 public IEnumerator<T> iterator() { | |
59 Node<T> currentNode = head.getNext(); | |
60 while (currentNode.getAttribute() != null) { | |
61 yield return (T)currentNode.getAttribute(); | |
62 currentNode = currentNode.getNext(); | |
63 } | |
64 } | |
65 | |
66 | |
67 public List<T> delete(int num) { | |
68 Node<T> newNode = head.delete(0, num); | |
69 if (newNode == null) | |
70 return this; | |
71 return new List<T>(newNode); | |
72 } | |
73 | |
74 public List<T> replace(int num, T attribute) { | |
75 Node<T> newHead = head.replaceNode(0, num, attribute); | |
76 if (newHead == null) | |
77 return this; | |
78 return new List<T>(newHead); | |
79 } | |
80 | |
81 public T tail() { | |
82 return index(length() - 1); | |
83 } | |
84 | |
85 // java code head. | |
86 public T headList() { | |
87 return index(0); | |
88 } | |
89 | |
90 public List<T> deleteLast() { | |
91 return delete(head.length() - 1); | |
92 } | |
93 | |
94 public List<T> deleteHead() { | |
95 return delete(0); | |
96 } | |
97 | |
98 public int length() { | |
99 return head.length(); | |
100 } | |
101 | |
102 public string toString() { | |
103 string pathString = "<"; | |
104 //IEnumerator<T> iterator = reverseIterator(); | |
105 while (true) { | |
106 // pathString += iterator.next(); | |
107 // if (iterator.hasNext()) | |
108 // pathString += ","; | |
109 // else | |
110 // break; | |
111 } | |
112 pathString += ">"; | |
113 return pathString; | |
114 } | |
115 | |
116 public List<T> append(List<T> list) { | |
117 IEnumerator<T> iterator = list.iterator(); | |
118 List<T> newList = this; | |
119 while (iterator.MoveNext()) { | |
120 T attribute = iterator.Current; | |
121 newList = newList.addLast(attribute); | |
122 } | |
123 return newList; | |
124 } | |
125 | |
126 // public IEnumerator<T> iterator() { | |
127 // Node<T> currentNode = head.getNext(); | |
128 // while (currentNode != null) { | |
129 // yield return currentNode; | |
130 // currentNode = currentNode.getNext(); | |
131 // } | |
132 // } | |
133 } |