Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs @ 4:79da77797f7e
list/List.cs fix, and not work addLast
author | Kazuma |
---|---|
date | Mon, 04 Jul 2016 03:50:34 +0900 |
parents | dec15de2c6ff |
children | 02b2ab7bffe6 |
comparison
equal
deleted
inserted
replaced
3:224f0f8b4f40 | 4:79da77797f7e |
---|---|
1 using UnityEngine; | 1 using UnityEngine; |
2 using System.Collections; | 2 using System.Collections; |
3 using System.Collections.Generic; | 3 using System.Collections.Generic; |
4 using System; | 4 using System; |
5 | 5 |
6 public class List<T> : System.Collections.Generic.List<T>, IEnumerable<T> { | 6 public class List<T> : IEnumerable<T> { |
7 private Node<T> head; | 7 private readonly Node<T> head; |
8 T[] _array; | |
9 T Count; | |
10 | |
11 | 8 |
12 public List() { | 9 public List() { |
13 this.head = new headNode<T>(); | 10 this.head = new headNode<T>(); |
14 } | 11 } |
15 | 12 |
16 // この部分がだめ。safeVarargsの部分 | 13 // T...はC#だとparamsらしい 可変引数型というみたいだ |
17 public List(T attributes) { | 14 public List(params T[] attributes) { |
18 List<T> list = new List<T> (); | 15 List<T> list = new List<T> (); |
19 //for (int i = 0; i < Convert.ToInt32(attributes.Count); i++) { | 16 foreach (T attribute_local in attributes) { |
20 list = list.addLast (attributes); | 17 list = list.addLast (attribute_local); |
21 //} | 18 } |
22 this.head = list.getHead(); | 19 this.head = list.getHead (); |
23 } | 20 } |
24 | 21 |
25 private List(Node<T> head) { | 22 private List(Node<T> head) { |
26 this.head = head; | 23 this.head = head; |
27 } | 24 } |
28 | 25 |
45 | 42 |
46 public T index(int num) { | 43 public T index(int num) { |
47 int count = 0; | 44 int count = 0; |
48 Node<T> currentNode = head.getNext(); | 45 Node<T> currentNode = head.getNext(); |
49 while (currentNode != null) { | 46 while (currentNode != null) { |
50 if (count == num) | 47 if (count == num) { |
51 return currentNode.getAttribute(); | 48 return currentNode.getAttribute (); |
49 } | |
52 currentNode = currentNode.getNext(); | 50 currentNode = currentNode.getNext(); |
53 count++; | 51 count++; |
54 } | 52 } |
55 return default(T); | 53 return default(T); |
56 } | 54 } |
59 Node<T> currentNode = head.getNext(); | 57 Node<T> currentNode = head.getNext(); |
60 while (currentNode.getAttribute() != null) { | 58 while (currentNode.getAttribute() != null) { |
61 yield return (T)currentNode.getAttribute(); | 59 yield return (T)currentNode.getAttribute(); |
62 currentNode = currentNode.getNext(); | 60 currentNode = currentNode.getNext(); |
63 } | 61 } |
62 } | |
63 | |
64 IEnumerator IEnumerable.GetEnumerator() | |
65 { | |
66 // call the generic version of the method | |
67 return this.GetEnumerator(); | |
68 } | |
69 | |
70 public IEnumerator<T> GetEnumerator() | |
71 { | |
72 return iterator (); | |
64 } | 73 } |
65 | 74 |
66 | 75 |
67 public List<T> delete(int num) { | 76 public List<T> delete(int num) { |
68 Node<T> newNode = head.delete(0, num); | 77 Node<T> newNode = head.delete(0, num); |