private void finishWork() { working.push(); time = 0; isWorking = false; working = idle; }
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 step[] addAllSteps(List <char> allStepChars) { step[] steps = new step[allStepChars.Count]; for (int i = 0; i < steps.Length; i++) { steps[i] = new step(allStepChars[i]); } return(steps); }
static void printSucc(step inStep) { foreach (step s in inStep.getSucc()) { Console.Write(s.getC()); } foreach (step s in inStep.getSucc()) { printSucc(s); } }
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); } }
static void Main() { //ta in indata som array av par [a,b] ==> a krävs för b char[,] input = getInput(); //spara varje steg som en char med referenser fram och bak. //lägg in de i random ordning //en referens start //sista blir null //sortera enligt input glöm inte att de ska vara i alfabetsordning! step[] steps = makeArr(input); step root = makeTree(input, steps); //!!!!! det chillar en sekund även fast det finns jobbb, fix //Stack<step> order = printOrderNew(root,steps); -- uppgiftA Console.WriteLine("S \t W1 \t W2 \t W3 \t W4 \t W5 \t Done"); int counter = 0; worker[] wArr = new worker[5]; //5 for (int i = 0; i < wArr.Length; i++) { wArr[i] = new worker(); } while (notDone(steps)) { foreach (worker w in wArr) { if (w.haveWork()) { w.work(); } if (!w.haveWork()) { if (isReadyStep(steps)) { w.setStep(findReadyStep(steps)); } } } Console.Write(counter + "\t" + wArr[0].getWork().getC() + "\t" + wArr[1].getWork().getC() + "\t" + wArr[2].getWork().getC() + "\t" + wArr[3].getWork().getC() + "\t" + wArr[4].getWork().getC() + "\t"); foreach (step s in steps) { if (s.getPushed()) { Console.Write(s.getC()); } } Console.WriteLine(); counter++; } }
static step[] sortArr(step[] steps) { int lowest; for (int i = 0; i < steps.Length; i++) { lowest = findLowestIndex(steps, i); if (steps[i].getC() > steps[lowest].getC()) { step temp = steps[i]; steps[i] = steps[lowest]; steps[lowest] = temp; } } return(steps); }
static Stack <step> printOrderNew(step root, step[] steps) { steps = sortArr(steps); Stack <step> order = new Stack <step>(); Stack <step> orderRev = new Stack <step>(); order.Push(root); root.push(); while (notEmpty(steps)) { step temp = getNext(steps); order.Push(temp); temp.push(); } while (order.Count != 0) { orderRev.Push(order.Pop()); } return(orderRev); }
public void addPred(step predIn) { pred.Add(predIn); }
public void addSucc(step succIn) { succ.Add(succIn); }
static step makeTree(char [,] input, step[] allSteps) { step root = sortSteps(allSteps, input); return(root); }
private static int compareSteps(step left, step right) { return(left.getC().CompareTo(right.getC())); }
public void setStep(step inStep) { working = inStep; isWorking = true; working.setWorked(); }