public static double ProveriMatematickiIzrazIliStaVec(string test) { StackList <string> stack = new StackList <string>(); int i = 0; try { for (i = 0; i < test.Length; ++i) { if (test[i] == ')') { double drugi = Double.Parse(stack.Top); stack.Pop(); char operacija = stack.Top[0]; stack.Pop(); double prvi = Double.Parse(stack.Top); stack.Pop(); stack.Pop(); stack.Push(izracunaj(prvi, drugi, operacija).ToString()); } else { stack.Push("" + test[i]); } } } catch (Exception e) { throw e; } return(Double.Parse(stack.Top)); }
public bool SyntaxError(lr_parser parser, Symbol curToken) { TypeCobolProgramParser tcpParser = parser as TypeCobolProgramParser; if (tcpParser.IsTrial) { return(true); } List <string> expected = ExpectedSymbols(parser, curToken); string symName = CodeElementTokenizer.CupTokenToString(curToken.sym); Symbol validSymbol = GetParserValidStackSymbol(parser, curToken); string text = validSymbol != null ? (validSymbol.value as CodeElement).Text : ""; string msg = string.Format("extraneous input '{0}' expecting {{{1}}}", text, string.Join(", ", expected)); System.Diagnostics.Debug.WriteLine(msg); CupParserDiagnostic diagnostic = new CupParserDiagnostic(msg, validSymbol, null); AddDiagnostic(diagnostic); //Try to add the last encountered statement in the stack if it is not already entered. StackList <Symbol> stack = tcpParser.getParserStack(); foreach (var symbol in stack) { if (symbol.value is StatementElement) { lr_parser stmtParser = CloneParser(parser, TypeCobolProgramSymbols.StatementEntryPoint, symbol.value as CodeElement, true); stmtParser.parse(); break; } } return(true); }
public static T DepthFirstSearch <T>(this Graph <T> graph, Func <T, bool> matchFunc) where T : class { if (graph.IsEmpty) { return(null); } graph.Nodes.ForEach(x => x._isVisited = false); IStack <GraphNode <T> > queue = new StackList <GraphNode <T> >(); queue.Push(graph.Nodes[0]); while (!queue.IsEmpty) { var node = queue.Pop(); if (node._isVisited) { continue; } if (matchFunc(node.Data)) { return(node.Data); } node.Edges.ForEach(x => queue.Push(x.To)); node._isVisited = true; } return(null); }
internal SpanSplitSequenceEnumerator(ReadOnlySpan <T> span, ReadOnlySpan <T> separator, StringSplitOptions stringSplitOptions) { Sequence = span; SplitOptions = stringSplitOptions; var separatorIndices = new StackList <int>(2); SeparatorLength = separator.Length; //https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs#L1579 for (int i = 0; i < span.Length; ++i) { if (span[i].Equals(separator[0]) && SeparatorLength <= span.Length - i) { if (SeparatorLength == 1 || span.Slice(i, SeparatorLength).SequenceEqual(separator)) { separatorIndices.Append(i); i += SeparatorLength - 1; } } } SeparatorIndices = separatorIndices; Index = 0; SeparatorIndex = 0; StartIndex = 0; Offset = 0; }
private IReadOnlyCollection <FlowComponent> getIdListRegionComponents() { var components = new List <FlowComponent>(); var rs = new UpdateRegionSet(); components.Add( new LineList( new EwfButton( new StandardButtonStyle("Add Item"), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( rs.ToCollection(), id: "idAdd", firstModificationMethod: () => parametersModification.ItemIds = (parametersModification.ItemIds.Any() ? parametersModification.ItemIds.Min() - 1 : 0).ToCollection() .Concat(parametersModification.ItemIds)))).ToCollection() .ToComponentListItem() .ToLineListItemCollection())); var stack = new StackList( info.ItemIds.Select(getIdItem), setup: new ComponentListSetup( itemInsertionUpdateRegions: new ItemInsertionUpdateRegion(rs.ToCollection(), () => parametersModification.ItemIds.First().ToString().ToCollection()) .ToCollection())); components.Add(new Section("Control List With ID Items", stack.ToCollection(), style: SectionStyle.Box)); return(components); }
internal Enumerator(StackList <T> stack) { _stack = stack; _version = stack._version; _index = -2; _currentElement = default; }
public void DefaultConstructorTest() { Stack stack = new StackList(); var list = getList(stack); Assert.IsNotNull(list); }
internal BTreeClass(int order) { Order = order; HalfFull = (order - 1) / 2; Root = new BTreeNode(order); Stack = new StackList(); Stack.Add(new StackItem()); }
/// <summary> /// Determines if the given token has been consumed. A token is consumed if it is /// present on the parser stack. /// </summary> /// <param name="parser">The parser</param> /// <param name="stack">The parser stack</param> /// <param name="curToken">The Token to check</param> /// <returns>true if the token is consumed, false otherwise</returns> public bool IsTokenConsumed(lr_parser parser, StackList <Symbol> stack, Symbol curToken) { if (curToken?.value == null) { return(false); } return(stack.Contains(curToken)); }
public void test_add_to_stack() { StackList <string> stack = new StackList <string>(); stack.Push("world"); Assert.AreEqual(1, stack.Count); }
public override bool SyntaxError(lr_parser parser, StackList <Symbol> stack, Symbol curToken) { LastMismatchedSymbol = null; bool bResult = base.SyntaxError(parser, stack, curToken); ((CobolWordsTokenizer)parser.getScanner()).EnterStopScanningMode(); ((CobolWordsTokenizer)parser.getScanner()).RevertLastToken(LastMismatchedSymbol); return(bResult); }
/// <summary> /// Returns the number of steps needed to change the contents of <paramref name="span"/> into <paramref name="other"/>. /// </summary> /// <param name="sourceRunes">The first text instance.</param> /// <param name="otherRunes">The second text instance.</param> /// <param name="comparison">How to compare two chars.</param> /// <returns>The number of steps needed to change <paramref name="span"/> into <paramref name="other"/>.</returns> /// <exception cref="NotImplementedException">The specified comparison is not implemented between two Runes with different ordinal values.</exception> private static int DamerauLevenshteinDistance(ref StackList <Rune> sourceRunes, ref StackList <Rune> otherRunes, StringComparison comparison = StringComparison.Ordinal) { int spanLength = sourceRunes.Length; int otherLength = otherRunes.Length; if (spanLength == 0) { return(otherLength); } if (otherLength == 0) { return(spanLength); } // Finding distances here utilizes a sort of grid. We use that as a lookup for our real word count. var costs = new Array2D <int>(stackalloc int[(spanLength + 1) * (otherLength + 1)], spanLength + 1, otherLength + 1); for (int x = 0; x <= spanLength; costs[x, 0] = x++) { ; } for (int y = 0; y <= otherLength; costs[0, y] = y++) { ; } for (int x = 1; x <= spanLength; ++x) { for (int y = 1; y <= otherLength; ++y) { var sourceRune = sourceRunes[x - 1]; var otherRune = otherRunes[y - 1]; int cost = RunesEqual(sourceRune, otherRune, comparison) ? 0 : 1; int insertion = costs[x, y - 1] + 1; int deletion = costs[x - 1, y] + 1; int substitution = costs[x - 1, y - 1] + cost; int distance = insertion.Min(deletion, substitution); if (x > 1 && y > 1 && RunesEqual(sourceRunes[x - 1], otherRunes[y - 2], comparison) && RunesEqual(sourceRunes[x - 2], otherRunes[y - 1], comparison)) { distance = Math.Min(distance, costs[x - 2, y - 2] + cost); } costs[x, y] = distance; } } return(costs[spanLength, otherLength]); }
public void test_remove_to_stack() { StackList <string> stack = new StackList <string>(); stack.Push("world"); stack.Push("ocean"); var value = stack.Pop(); Assert.AreEqual("ocean", value); }
//-------- public override string ToString() { BluetoothStackConfigElement[] arr = new BluetoothStackConfigElement[StackList.Count]; StackList.CopyTo(arr, 0); string slConcat = "{" + string.Join(", ", Array.ConvertAll <BluetoothStackConfigElement, string>(arr, delegate(BluetoothStackConfigElement inp) { return((inp == null) ? "(null)" : inp.Name); })) + "}"; // return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "[BluetoothFactorySection: OneStackOnly: {0}, ReportAllErrors: {1}, StackList: {2}, FooBar1: {3}]", this.OneStackOnly, this.ReportAllErrors, slConcat, this.FooBar1)); }
public void test_remove_empty() { StackList <string> stack = new StackList <string>(); stack.Push("world"); stack.Push("ocean"); stack.Pop(); stack.Pop(); Assert.AreEqual(0, stack.Count); }
/// <summary> /// 构造拓扑排序对象 /// </summary> /// <param name="g">有向图</param> public TopoLogicalOrder(GraphDigraph g) { // 检测图是否有环 GraphDirectedCyle cycle = new GraphDirectedCyle(g); bool hasCycle = cycle.hasCycle(); if (!hasCycle) { DepthFirstOrder depth = new DepthFirstOrder(g); orderStack = depth.reversePost(); } }
public TData Search(float?costDepthLimit = null) { NextCostThreshhold = float.MaxValue; IStack <TreeNode <TData> > stack = new StackList <TreeNode <TData> >(); stack.Push(_tree.Root); while (!stack.IsEmpty) { CurrentNode = stack.Pop(); if (_matchFunc(CurrentNode.Data)) { return(CurrentNode.Data); } var actions = _actionsListFunc(CurrentNode.Data); CurrentNode.Children = new List <TreeNode <TData> >(); foreach (var action in actions) { var newNode = new TreeNode <TData> { Parent = CurrentNode, Data = _actionApplierFunc(CurrentNode.Data, action), Cost = CurrentNode.Cost + _actionCostFunc(CurrentNode.Data, action) }; CurrentNode.Children.Add(newNode); } // Load new children onto stack CurrentNode.Children.ForEach(x => { if (costDepthLimit == null || costDepthLimit.Value >= x.Cost) { stack.Push(x); } else if (x.Cost < NextCostThreshhold) { NextCostThreshhold = x.Cost; } }); // Update counts & notifications OnNodeExpanded(); CurrentNode.Children.ForEach(x => OnNodeGenerated()); NodesRetainedCount = stack.Count; } return(null); }
public static void TraverseDepthFirst <T>(this SearchTree <T> tree, Action <T> action) where T : class { IStack <TreeNode <T> > stack = new StackList <TreeNode <T> >(); stack.Push(tree.Root); while (!stack.IsEmpty) { var node = stack.Pop(); action(node.Data); node.Children.ForEach(stack.Push); } }
public StackView(ProfileData data, DisplayOptions options) { list = new StackList (data, options); ScrolledWindow sw = new ScrolledWindow (); sw.Add (list); sw.ShowAll (); Add1 (sw); detail = new StackDetail (data, options); detail.CurrentItem = list.SelectedItem; list.Selection.Changed += delegate { detail.CurrentItem = list.SelectedItem; }; Add2 (detail); Position = 200; }
public CommandLine(string assetname) : base(assetname) { if (TextFont != null) { TextFont.Color = Color.White; } vc = new StackList <char>(); ac = new StackList <char>(); acursor = cursor; timer = 0.5f; }
public object Pop() { if (StackList.Count() == 0) { throw new InvalidOperationException(); } else { object temp = StackList[StackList.Count() - 1]; StackList.Remove(StackList[StackList.Count() - 1]); return(temp); } }
public override void Clear() { if (StackList != null) { for (int i = 0; i < StackList.Count; i++) { if (StackList[i] != null) { StackList[i].Clear(); } } StackList.Clear(); } }
public void PeekTest() { Stack stack = new StackList(); Assert.IsNull(stack.Peek()); stack.Push(5); Assert.AreEqual(5, stack.Peek()); Assert.AreEqual(5, stack.Peek()); stack.Push(7); Assert.AreEqual(7, stack.Peek()); Assert.AreEqual(7, stack.Peek()); }
/// <summary> /// 创建一个顶点排序对象 生成顶点线性队列 /// </summary> /// <param name="g"></param> public DepthFirstOrder(GraphDigraph g) { // 初始markeds 数组 this.markeds = new bool[g.countV()]; // 初始化 reversePost stack 栈 this.reversePostStack = new StackList <int>(); // 遍历图中的每一个顶点,让每一个定点做作为入口,完成一次深度优先搜索 for (int v = 0; v < g.countV(); v++) { if (!this.markeds[v]) { dfs(g, v); } } }
public void PushTest() { Stack stack = new StackList(); stack.Push(3); stack.Push(5); stack.Push(7); var outputStack = getList(stack); Assert.AreEqual(3, outputStack.Count); Assert.AreEqual(7, outputStack.First()); Assert.AreEqual(7, outputStack[0]); Assert.AreEqual(5, outputStack[1]); Assert.AreEqual(3, outputStack[2]); }
/// <summary> /// Makes a string from a stacklist. /// </summary> /// <param name="c">The stacklist.</param> /// <param name="back">The direction the stacklist needs to be read.</param> /// <returns></returns> private string StackToString(StackList <char> c, bool back = false) { string s = ""; for (int i = 0; i < c.Count; i++) { if (!back) { s = c[i] + s; } else { s += c[i]; } } return(s); }
/*-----------------------------------------------------------*/ /*--- Constructor(s) ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Constructor to build a virtual stack out of a real stack. */ public virtual_parse_stack(StackList <Symbol> shadowing_stack) { /* sanity check */ if (shadowing_stack == null) { throw new System.Exception( "Internal parser error: attempt to create null virtual stack"); } /* Set up our internals */ real_stack = shadowing_stack; vstack = new Stack <int>(); real_next = 0; /* get one element onto the virtual portion of the stack */ get_from_real(); }
/// <summary> /// 栈 测试 /// </summary> private static void StackListTest() { StackList <Student> list = new StackList <Student>(); for (int i = 0; i < 5; i++) { list.push(new Student() { cardID = i, name = "sun" + i }); } Console.WriteLine("StackList Length: " + list.length()); IEnumerator tor = list.GetEnumerator(); while (tor.MoveNext()) { if (tor.Current is Student) { Student s = tor.Current as Student; Console.WriteLine("cardID: " + s.cardID); } else { Console.WriteLine("LinkList GetEnumerator is null."); } } Student popStu = list.pop(); Console.WriteLine("StackList pop Stu: " + popStu.cardID); Console.WriteLine("StackList Length: " + list.length()); IEnumerator tor1 = list.GetEnumerator(); while (tor1.MoveNext()) { if (tor1.Current is Student) { Student s = tor1.Current as Student; Console.WriteLine("cardID: " + s.cardID); } else { Console.WriteLine("LinkList GetEnumerator is null."); } } }
/// <summary> /// Get the first valid Symbol on the parser stack having a value. /// </summary> /// <param name="parser">The parser stack</param> /// <param name="curToken">The current Symbol</param> /// <returns>The first valid symbol if any, null otherwise</returns> protected virtual Symbol GetParserValidStackSymbol(lr_parser parser, StackList <Symbol> stack, Symbol curToken) { if (curToken != null && curToken.value != null) { return(curToken); } //lookback in the stack to find a Symbol having a valid value. Symbol lastValid = null; foreach (Symbol s in stack) {//The first one will be the top of the stack wil be the last symbol encountered if (s.value != null) { lastValid = s; break; } } return(lastValid); }
public StackList <int> pathTo(int v) { if (!hasPathTo(v)) { return(null); } // 创建栈对象 保存路径中的所有顶点 StackList <int> path = new StackList <int>(); // 通过循环从顶点v开始一直往前找,知道找到起点 for (int x = v; x != this.s; x = edgeTo[x]) { path.push(x); } // 把起点s放进去 path.push(this.s); return(path); }
/// <summary> /// Get the first valid Symbol on the parser stack having a value. /// </summary> /// <param name="parser">The parser stack</param> /// <param name="curToken">The current Symbol</param> /// <returns>The first valid symbol if any, null otherwise</returns> private static Symbol GetParserValidStackSymbol(lr_parser parser, Symbol curToken) { if (curToken.value != null) { return(curToken); } //lookback in the stack to find a Symbol having a valid value. StackList <Symbol> stack = ((TypeCobolProgramParser)parser).getParserStack(); Symbol lastValid = null; foreach (Symbol s in stack) { if (s.value != null) { lastValid = s; } } return(lastValid); }
void Start() { // Get Inventory's references InventoryManager inventory = Inventory.Finder.GetInventory(); pickupsRef = inventory.GetStack(); itemCountRef = inventory.GetItemCount(); }