using UnityEngine; using System.Collections; using System.Collections.Generic; public class NetworkNodePath : NodePath { LinkedList Path; public NetworkNodePath () { Path = new LinkedList(); Path.AddFirst(-1); } public NetworkNodePath (NodePath path){ Path = new LinkedList(); foreach(int p in path) { Path.AddLast(p); } } private NetworkNodePath (LinkedList path) { this.Path = path; } public IEnumerator iterator () { // iterator error. yield return this.Path.GetEnumerator().Current; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public IEnumerator GetEnumerator() { return iterator (); } public NodePath add (int pos) { LinkedList newPath = copyPath(); newPath.AddLast(pos); return new NetworkNodePath(newPath); } public NodePath addHead(int pos) { // still java code. LinkedList newPath = copyPath(); newPath.AddFirst(pos); return new NetworkNodePath(newPath); } public Pair pop () { LinkedList cPath = copyPath(); int e = cPath.First.Value; cPath.RemoveFirst(); return new Pair(e, new NetworkNodePath(cPath)); } public int size () { return this.Path.Count; } public LinkedList copyPath(){ LinkedList newPath = new LinkedList(); foreach(int i in this.Path) { newPath.AddLast(i); } return newPath; } public override string ToString () { return Path.ToString(); } public NodePath tail() { this.Path.RemoveLast(); return new NetworkNodePath(this.Path); } public Pair last () { int lastValue = this.Path.Last.Value; this.Path.RemoveLast(); return new Pair(lastValue, new NetworkNodePath(this.Path)); } }