using UnityEngine; using System.Collections; using System.Collections.Generic; using System; public class List : System.Collections.Generic.List, IEnumerable { private Node head; T[] _array; T Count; public List() { this.head = new headNode(); } // この部分がだめ。safeVarargsの部分 public List(T attributes) { List list = new List (); //for (int i = 0; i < Convert.ToInt32(attributes.Count); i++) { list = list.addLast (attributes); //} this.head = list.getHead(); } private List(Node head) { this.head = head; } public Node getHead() { return head; } public List add(int num, T attribute) { Node newHead = head.add(0, num, attribute); if (newHead == null) return this; return new List(newHead); } public List addLast(T attribute) { Node newHead = head.addLast(attribute); return new List(newHead); } public T index(int num) { int count = 0; Node currentNode = head.getNext(); while (currentNode != null) { if (count == num) return currentNode.getAttribute(); currentNode = currentNode.getNext(); count++; } return default(T); } public IEnumerator iterator() { Node currentNode = head.getNext(); while (currentNode.getAttribute() != null) { yield return (T)currentNode.getAttribute(); currentNode = currentNode.getNext(); } } public List delete(int num) { Node newNode = head.delete(0, num); if (newNode == null) return this; return new List(newNode); } public List replace(int num, T attribute) { Node newHead = head.replaceNode(0, num, attribute); if (newHead == null) return this; return new List(newHead); } public T tail() { return index(length() - 1); } // java code head. public T headList() { return index(0); } public List deleteLast() { return delete(head.length() - 1); } public List deleteHead() { return delete(0); } public int length() { return head.length(); } public string toString() { string pathString = "<"; //IEnumerator iterator = reverseIterator(); while (true) { // pathString += iterator.next(); // if (iterator.hasNext()) // pathString += ","; // else // break; } pathString += ">"; return pathString; } public List append(List list) { IEnumerator iterator = list.iterator(); List newList = this; while (iterator.MoveNext()) { T attribute = iterator.Current; newList = newList.addLast(attribute); } return newList; } // public IEnumerator iterator() { // Node currentNode = head.getNext(); // while (currentNode != null) { // yield return currentNode; // currentNode = currentNode.getNext(); // } // } }