static Stack <step> makeOrder(step root, List <step> order) { foreach (step s in root.getPred()) { if (!s.getPushed()) { order.Add(s); s.push(); Console.Write(s.getC()); Console.WriteLine(" added"); } } if (order.Count != 0) { order.Sort(compareSteps); step top = order[0]; Console.Write(top.getC()); Console.WriteLine(" pushed"); order.Remove(top); Stack <step> orderStack = makeOrder(top, order); orderStack.Push(top); return(orderStack); } return(new Stack <step>()); }
static void printOrder(step root) { List <step> order = new List <step>(); root.push(); Stack <step> orderStack = makeOrder(root, order); while (orderStack.Count != 0) { Console.Write(orderStack.Pop().getC()); } Console.Write(root.getC()); }
static void printPred(step root) { Console.Write(root.getC()); Console.Write(": "); foreach (step s in root.getPred()) { Console.Write(s.getC()); } Console.WriteLine(); foreach (step s in root.getPred()) { printPred(s); } }
private static int compareSteps(step left, step right) { return(left.getC().CompareTo(right.getC())); }