public static string LLToString(LinkedListA <string> linkedList) { string result = ""; for (LinkedListNodeA <string> c = linkedList.first; c != null; c = c.next) { result += c.item; } return(result); }
public LinkedListA <string> DoIterations(int n) { LinkedListA <string> ll = StringToLL(axiom); for (int i = 0; i < n; i++) { for (LinkedListNodeA <string> c = ll.first; c != null; c = c.next) { replaceNode(ll, c); } } iterations = n; return(ll); }
public void Enqueue(T item) { LinkedListNodeA <T> oldLast = last; last = new LinkedListNodeA <T>(); last.item = item; last.next = null; if (IsEmpty()) { first = last; } if (oldLast != null) { oldLast.next = last; } last.previous = oldLast; n++; }
// repalce node with linkedlistA public void Replace(LinkedListNodeA <T> node, LinkedListA <T> linkedList) { if (linkedList.IsEmpty()) { return; } if (node.previous == null) { first = linkedList.first; } else { Link(node.previous, linkedList.first); } if (node.next != null) { Link(linkedList.last, node.next); } }
public T Dequeue() { if (IsEmpty()) { return(default(T)); } T item = first.item; first = first.next; n--; if (IsEmpty()) { last = null; } else { first.previous = null; } return(item); }
private void replaceNode(LinkedListA <string> ll, LinkedListNodeA <string> node) { if (Regex.IsMatch(node.item, @"^[a-zA-Z]+$")) { if (grammar.ContainsKey(node.item)) { List <Rule> rules = grammar[node.item]; float totalProbability = 0; // roll dice against each rule for (var i = 0; i < rules.Count; i++) { totalProbability += rules[i].probability; if (totalProbability >= UnityEngine.Random.value) { // apply rule ll.Replace(node, StringToLL(rules[i].str)); break; } } } } }
private void Link(LinkedListNodeA <T> a, LinkedListNodeA <T> b) { a.next = b; b.previous = a; }