Mercurial > hg > Database > jungle-sharp
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs Tue Jun 21 17:11:12 2016 +0900 @@ -0,0 +1,133 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class List<T> : System.Collections.Generic.List<T>, IEnumerable<T> { + private Node<T> head; + T[] _array; + T Count; + + + public List() { + this.head = new headNode<T>(); + } + + // この部分がだめ。safeVarargsの部分 + public List(T attributes) { + List<T> list = new List<T> (); + //for (int i = 0; i < Convert.ToInt32(attributes.Count); i++) { + list = list.addLast (attributes); + //} + this.head = list.getHead(); + } + + private List(Node<T> head) { + this.head = head; + } + + public Node<T> getHead() { + return head; + } + + public List<T> add(int num, T attribute) { + Node<T> newHead = head.add(0, num, attribute); + if (newHead == null) + return this; + return new List<T>(newHead); + } + + public List<T> addLast(T attribute) { + Node<T> newHead = head.addLast(attribute); + return new List<T>(newHead); + } + + + public T index(int num) { + int count = 0; + Node<T> currentNode = head.getNext(); + while (currentNode != null) { + if (count == num) + return currentNode.getAttribute(); + currentNode = currentNode.getNext(); + count++; + } + return default(T); + } + + public IEnumerator<T> iterator() { + Node<T> currentNode = head.getNext(); + while (currentNode.getAttribute() != null) { + yield return (T)currentNode.getAttribute(); + currentNode = currentNode.getNext(); + } + } + + + public List<T> delete(int num) { + Node<T> newNode = head.delete(0, num); + if (newNode == null) + return this; + return new List<T>(newNode); + } + + public List<T> replace(int num, T attribute) { + Node<T> newHead = head.replaceNode(0, num, attribute); + if (newHead == null) + return this; + return new List<T>(newHead); + } + + public T tail() { + return index(length() - 1); + } + + // java code head. + public T headList() { + return index(0); + } + + public List<T> deleteLast() { + return delete(head.length() - 1); + } + + public List<T> deleteHead() { + return delete(0); + } + + public int length() { + return head.length(); + } + + public string toString() { + string pathString = "<"; + //IEnumerator<T> iterator = reverseIterator(); + while (true) { +// pathString += iterator.next(); +// if (iterator.hasNext()) +// pathString += ","; +// else +// break; + } + pathString += ">"; + return pathString; + } + + public List<T> append(List<T> list) { + IEnumerator<T> iterator = list.iterator(); + List<T> newList = this; + while (iterator.MoveNext()) { + T attribute = iterator.Current; + newList = newList.addLast(attribute); + } + return newList; + } + +// public IEnumerator<T> iterator() { +// Node<T> currentNode = head.getNext(); +// while (currentNode != null) { +// yield return currentNode; +// currentNode = currentNode.getNext(); +// } +// } +}