private void UpdateOpenNodes(Context context) { NodeStack openNodes = context._openNodes[guid]; NodeStack tmpNodes = context._tempNodes[guid]; NodeStack oldOpenNodes = context._oldOpenNodes[guid]; while (openNodes.Count > 0 /*&& oldOpenNodes.Count > 0*/) { if (openNodes.Count > oldOpenNodes.Count) { tmpNodes.Push(openNodes.Pop()); } else if (openNodes.Count < oldOpenNodes.Count) { oldOpenNodes.Pop()._close(context); } else if (openNodes.Peek().guid != oldOpenNodes.Peek().guid) { tmpNodes.Push(openNodes.Pop()); oldOpenNodes.Pop()._close(context); } else { break; } } while (tmpNodes.Count > 0) { oldOpenNodes.Push(tmpNodes.Pop()); } }
private void StartGraphNode(IAstNode node) { var graphNode = new Node( ) { Id = CreateNodeId(node), Label = node.GetType( ).Name, Category = "TreeNode" }; graphNode.Properties.Add("SourceInteval", node.Location.ToString( )); if (NodeStack.Count > 0) { var link = new Link( ) { Source = NodeStack.Peek( ).Id, Target = graphNode.Id }; Graph.Links.Add(link); } Graph.Nodes.Add(graphNode); NodeStack.Push(graphNode); }
static void Main(string[] args) { var stack = new NodeStack <string>(); stack.Push("Tom"); stack.Push("Alice"); stack.Push("Bob"); stack.Push("Kate"); foreach (var item in stack) { Console.WriteLine(item); } Console.WriteLine(); string header = stack.Peek(); Console.WriteLine($"Верхушка стека: {header}"); Console.WriteLine(); header = stack.Pop(); foreach (var item in stack) { Console.WriteLine(item); } }
public void TestPeekException() { NodeStack <string> stack = new NodeStack <string>(); string actual = stack.Peek(); string excerted = "Стек пуст"; Assert.AreEqual(excerted, actual); }
static int GetAttributeIndentDepth (NodeStack nodes) { var node = nodes.Peek (); if (node is XElement && !node.IsEnded) return 1; if (node is XAttribute) return node.IsEnded? 1 : 2; return 0; }
static int GetAttributeIndentDepth(NodeStack nodes) { var node = nodes.Peek(); if (node is XElement && !node.IsEnded) { return(1); } if (node is XAttribute) { return(node.IsEnded? 1 : 2); } return(0); }
public void TestPeekElement() { NodeStack <string> stack = new NodeStack <string>(); stack.Push("A"); stack.Push("B"); stack.Push("C"); stack.Push("D"); stack.Push("E"); string actual = stack.Peek(); string excerted = "E"; Assert.AreEqual(excerted, actual); }
static void Main(string[] args) { stack = new NodeStack <string>(); stack.CollectionChanged += Stack_CollectionChanged; int key = 1, answer; string value = "", peek, del; while (key != 0) { Console.Clear(); Console.Write( " Menu:\n" + "1: Add value to stack.\n" + "2: Show all values from stack.\n" + "3: Show top value of stack.\n" + "4: Delete value from stack.\n" + "0: Exit.\n" + "Enter key: "); key = Convert.ToInt32(Console.ReadLine()); switch (key) { //добавляем элементы в стек case 1: Console.Write("\nHow many values do you want to insert?: "); answer = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < answer; i++) { Console.Write("Add value: "); value = Console.ReadLine(); stack.Push(value); if (message != null) { Console.WriteLine($"\n{message}\n"); } } break; //выводим вместимое стека case 2: try { stack.ReturnEmpty(); Console.WriteLine("\nStack values:\n"); foreach (var elem in stack) { Console.WriteLine(elem); } Console.WriteLine(); } catch (InvalidOperationException err) { Console.WriteLine(err.Message); } break; case 3: try { stack.ReturnEmpty(); peek = stack.Peek(); Console.WriteLine($"\nTop value in stack: {peek}\n"); } catch (InvalidOperationException err) { Console.WriteLine(err.Message); } break; case 4: try { stack.ReturnEmpty(); del = stack.Pop(); Console.WriteLine($"\nDeleted value is: {del}"); if (message != null) { Console.WriteLine($"\n{message}\n"); } } catch (InvalidOperationException err) { Console.WriteLine(err.Message); } break; case 0: return; default: Console.WriteLine("\nWrong input! Try again.\n"); break; } Console.Write("Press any key to continue..."); Console.ReadKey(); } }