private void WorkWithStack(int maxSize) { ShowName("Stack"); StackStruct <long> stack = new StackStruct <long>(maxSize); Fill(stack, maxSize); try { stack.Insert(6); } catch (Exception e) { Console.WriteLine(e.Message); } Remove(stack); try { stack.Remove(); } catch (Exception e) { Console.WriteLine(e.Message); } ShowEndMessage(); }
public long MathWithStack(int number) { StackStruct <long> stack = new StackStruct <long>(500); long answer = 0; while (number > 0) { stack.Insert(number--); } while (!stack.IsEmpty()) { answer += stack.Remove(); } return(answer); }
/// <summary> /// initializes lim and low in the subtree /// </summary> /// <param name="curLim">the root of the subtree</param> /// <param name="v">the low[v]</param> private void InitLowLimParentAndLeavesOnSubtree(int curLim, int v) { Stack <StackStruct> stack = new Stack <StackStruct>(); IEnumerator outEnum = this.graph.OutEdges(v).GetEnumerator(); IEnumerator inEnum = this.graph.InEdges(v).GetEnumerator(); stack.Push(new StackStruct(v, outEnum, inEnum));//vroot is 0 here low[v] = curLim; while (stack.Count > 0) { StackStruct ss = stack.Pop(); v = ss.v; outEnum = ss.outEnum; inEnum = ss.inEnum; //for sure we will have a descendant with the lowest number curLim since curLim may only grow //from the current value ProgressStep(); bool done; do { done = true; while (outEnum.MoveNext()) { NetworkEdge e = outEnum.Current as NetworkEdge; if (!e.inTree || low[e.Target] > 0) { continue; } stack.Push(new StackStruct(v, outEnum, inEnum)); v = e.Target; parent[v] = e; low[v] = curLim; outEnum = this.graph.OutEdges(v).GetEnumerator(); inEnum = this.graph.InEdges(v).GetEnumerator(); } while (inEnum.MoveNext()) { NetworkEdge e = inEnum.Current as NetworkEdge; if (!e.inTree || low[e.Source] > 0) { continue; } stack.Push(new StackStruct(v, outEnum, inEnum)); v = e.Source; low[v] = curLim; parent[v] = e; outEnum = this.graph.OutEdges(v).GetEnumerator(); inEnum = this.graph.InEdges(v).GetEnumerator(); done = false; break; } } while (!done); //finally done with v lim[v] = curLim++; if (lim[v] == low[v]) { leaves.Add(v); } } }