Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-network/operations/NetworkNodePath.cs @ 12:b71d9ea6bd8e
Add Network Operation Class. this codes can not test yet.
author | Kazuma |
---|---|
date | Sun, 23 Oct 2016 12:25:57 +0900 |
parents | |
children | 4c8932dad7b2 |
comparison
equal
deleted
inserted
replaced
11:220433691c2e | 12:b71d9ea6bd8e |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 using System.Collections.Generic; | |
4 | |
5 public class NetworkNodePath : NodePath { | |
6 LinkedList<int> Path; | |
7 | |
8 public NetworkNodePath () { | |
9 Path = new LinkedList<int>(); | |
10 Path.AddFirst(-1); | |
11 } | |
12 | |
13 public NetworkNodePath (NodePath path){ | |
14 Path = new LinkedList<int>(); | |
15 foreach(int p in path) { | |
16 Path.AddLast(p); | |
17 } | |
18 } | |
19 | |
20 private NetworkNodePath (LinkedList<int> path) { | |
21 this.Path = path; | |
22 } | |
23 | |
24 public IEnumerator<int> iterator () { // iterator error. | |
25 yield return this.Path.GetEnumerator().Current; | |
26 } | |
27 | |
28 IEnumerator IEnumerable.GetEnumerator() | |
29 { | |
30 return this.GetEnumerator(); | |
31 } | |
32 | |
33 public IEnumerator<int> GetEnumerator() | |
34 { | |
35 return iterator (); | |
36 } | |
37 | |
38 public NodePath add (int pos) { | |
39 LinkedList<int> newPath = copyPath(); | |
40 newPath.AddLast(pos); | |
41 return new NetworkNodePath(newPath); | |
42 } | |
43 | |
44 public NodePath addHead(int pos) { // still java code. | |
45 LinkedList<int> newPath = copyPath(); | |
46 newPath.AddFirst(pos); | |
47 return new NetworkNodePath(newPath); | |
48 } | |
49 | |
50 public Pair<int, NodePath> pop () { | |
51 LinkedList<int> cPath = copyPath(); | |
52 int e = cPath.First.Value; | |
53 cPath.RemoveFirst(); | |
54 return new Pair<int, NodePath>(e, new NetworkNodePath(cPath)); | |
55 } | |
56 | |
57 public int size () { | |
58 return this.Path.Count; | |
59 } | |
60 | |
61 | |
62 public LinkedList<int> copyPath(){ | |
63 LinkedList<int> newPath = new LinkedList<int>(); | |
64 foreach(int i in this.Path) { | |
65 newPath.AddLast(i); | |
66 } | |
67 return newPath; | |
68 } | |
69 | |
70 public override string ToString () { | |
71 return Path.ToString(); | |
72 } | |
73 | |
74 public NodePath tail() { | |
75 this.Path.RemoveLast(); | |
76 return new NetworkNodePath(this.Path); | |
77 } | |
78 | |
79 public Pair<int, NodePath> last () { | |
80 int lastValue = this.Path.Last.Value; | |
81 this.Path.RemoveLast(); | |
82 return new Pair<int, NodePath>(lastValue, new NetworkNodePath(this.Path)); | |
83 } | |
84 | |
85 | |
86 | |
87 } |