/// <summary> /// 在指定位置之前插入一个元素。 /// </summary> /// <param name="item">要插入的元素。</param> /// <param name="index">插入位置的下标。</param> public void InsertBefore(TItem item, int index) { if (index == 0) { InsertFront(item); return; } if (index >= _count || index < 0) { throw new IndexOutOfRangeException(); } var current = Find(index); var node = new DoubleNode <TItem> { Next = current, Prev = current.Prev, Item = item }; current.Prev.Next = node; current.Prev = node; _count++; }
/// <summary> /// 在指定位置之后插入一个元素。 /// </summary> /// <param name="item">要插入的元素。</param> /// <param name="index">查找元素的下标。</param> public void InsertAfter(TItem item, int index) { if (index == _count - 1) { InsertRear(item); return; } if (index >= _count || index < 0) { throw new IndexOutOfRangeException(); } var current = Find(index); var node = new DoubleNode <TItem> { Prev = current, Next = current.Next, Item = item }; current.Next.Prev = node; current.Next = node; _count++; }
/// <summary> /// 默认构造函数,建立一个双端栈。 /// </summary> public DeStack() { this.first = null; this.last = null; this.leftcount = 0; this.rightcount = 0; }
/// <summary> /// 删除指定位置的元素。 /// </summary> /// <param name="index">要删除元素的下标。</param> /// <returns></returns> public Item Delete(int index) { if (index < 0 || index >= this.count) { throw new IndexOutOfRangeException(); } if (index == 0) { return(DeleteFront()); } if (index == this.count - 1) { return(DeleteRear()); } DoubleNode <Item> current = Find(index); Item temp = current.item; current.prev.next = current.next; current.next.prev = current.prev; this.count--; return(temp); }
public DequeEnumerator(DoubleNode <Item> first) { this.current = new DoubleNode <Item>(); this.current.next = first; this.current.prev = null; this.first = this.current; }
/// <summary> /// 在指定位置之后插入一个元素。 /// </summary> /// <param name="item">要插入的元素。</param> /// <param name="index">查找元素的下标。</param> public void InsertAfter(Item item, int index) { if (index == this.count - 1) { InsertRear(item); return; } if (index >= this.count || index < 0) { throw new IndexOutOfRangeException(); } DoubleNode <Item> current = Find(index); DoubleNode <Item> node = new DoubleNode <Item>() { prev = current, next = current.next, item = item }; current.next.prev = node; current.next = node; this.count++; }
public string ConvertToString(DoubleNode<StringId> tree) { var lines = new DoubleNodeConverter().ConvertDoubleNode(tree); var stringBuilder = new StringBuilder(); lines.ForEach(line => stringBuilder.AppendLine(line)); return stringBuilder.ToString(); }
/// <summary> /// 在指定位置之前插入一个元素。 /// </summary> /// <param name="item">要插入的元素。</param> /// <param name="index">插入位置的下标。</param> public void InsertBefore(Item item, int index) { if (index == 0) { InsertFront(item); return; } if (index >= this.count || index < 0) { throw new IndexOutOfRangeException(); } DoubleNode <Item> current = Find(index); DoubleNode <Item> node = new DoubleNode <Item>() { next = current, prev = current.prev, item = item }; current.prev.next = node; current.prev = node; this.count++; }
public DoubleNode Double(string value) { DoubleNode doubleNode = new DoubleNode(); Match(TokenType.DOUBLE); doubleNode.Value = double.Parse(value); return(doubleNode); }
public bool MoveNext() { if (this.current.next == null) { return(false); } this.current = this.current.next; return(true); }
public void DeleteHead() { if (last == null) { return; } last.next = null; last = null; }
public void DeleteEnd() { if (next == null) { return; } next.last = null; next = null; }
public bool MoveNext() { if (current.next == null) { return(false); } current = current.next; return(true); }
bool IEnumerator.MoveNext() { if (current.next == null) { return(false); } current = current.next; return(true); }
public DoubleNode Flatten(DoubleNode head) { if (head == null) { return(null); } FlatternHealper(head); return(head); }
public bool MoveNext() { if (_current.Next == null) { return(false); } _current = _current.Next; return(true); }
bool IEnumerator.MoveNext() { if (_current.Next == null) { return(false); } _current = _current.Next; return(true); }
public IEnumerator <DoubleNode <T> > GetEnumerator() { this._current = this._head; while (this._current != null) { yield return(this._current); this._current = this._current.Next; } }
[Test] // 1.3.31 public void DoubleNode() { var firstNode = BuildFiveDoubleIntNodesAscending(); var topNode = new DoubleNode <int> { Item = 999 }; DoubleNode <int> .InsertAtBeginning(firstNode, topNode); Assert.AreEqual(999, DoubleNode <int> .First(firstNode).Item); var newLastNode = new DoubleNode <int> { Item = 100 }; DoubleNode <int> .InsertAtEnd(firstNode, newLastNode); Assert.AreEqual(100, DoubleNode <int> .Last(topNode).Item); var lastNode = newLastNode.Previous; Assert.AreEqual(999, DoubleNode <int> .First(newLastNode).Item); DoubleNode <int> .RemoveFromBeginning(newLastNode); Assert.AreEqual(4, DoubleNode <int> .First(newLastNode).Item); Assert.AreEqual(100, DoubleNode <int> .Last(firstNode).Item); DoubleNode <int> .RemoveFromEnd(firstNode); Assert.AreEqual(0, DoubleNode <int> .Last(firstNode).Item); Assert.AreEqual(4, DoubleNode <int> .First(lastNode).Item); DoubleNode <int> .InsertBefore(firstNode, new DoubleNode <int> { Item = 555 }); Assert.AreEqual(555, firstNode.Previous.Item); Assert.AreEqual(4, firstNode.Item); Assert.AreEqual(3, firstNode.Next.Item); var new222 = new DoubleNode <int> { Item = 222 }; DoubleNode <int> .InsertAfter(firstNode, new222); Assert.AreEqual(222, firstNode.Next.Item); Assert.AreEqual(3, firstNode.Next.Next.Item); Assert.AreEqual(222, firstNode.Next.Item); DoubleNode <int> .RemoveNode(firstNode, new222); Assert.AreEqual(3, firstNode.Next.Item); Assert.AreEqual(4, firstNode.Next.Previous.Item); }
public void SparqlOperatorApplicationSubtractNumeric10() { List <IValuedNode> ns = new List <IValuedNode>() { new DoubleNode(null, 1), new DoubleNode(null, 2) }; IValuedNode expected = new DoubleNode(null, -1); this.TestApplication(SparqlOperatorType.Subtract, ns, expected, false); }
/// <summary> /// Evaluates the expression. /// </summary> /// <param name="context">Evaluation Context.</param> /// <param name="bindingID">Binding ID.</param> /// <returns></returns> public IValuedNode Evaluate(SparqlEvaluationContext context, int bindingID) { // Ensure we return a consistent value when evaluating a set we have already seen if (_bindings.TryGetValue(bindingID, out IValuedNode result)) { return(result); } result = new DoubleNode(null, _rnd.NextDouble()); _bindings[bindingID] = result; return(result); }
public void SparqlOperatorApplicationDivideNumeric10() { List <IValuedNode> ns = new List <IValuedNode>() { new DoubleNode(null, 1), new DoubleNode(null, 2) }; IValuedNode expected = new DoubleNode(null, 0.5d); this.TestApplication(SparqlOperatorType.Divide, ns, expected, false); }
public void SparqlOperatorApplicationMultiplyNumeric10() { List <IValuedNode> ns = new List <IValuedNode>() { new DoubleNode(null, 3), new DoubleNode(null, 6) }; IValuedNode expected = new DoubleNode(null, 18); this.TestApplication(SparqlOperatorType.Multiply, ns, expected, false); }
IEnumerator <T> IEnumerable <T> .GetEnumerator() { DoubleNode <T> current = first; while (current != null) { yield return(current.value); current = current.Next; } }
public void SparqlOperatorApplicationAddNumeric9() { List <IValuedNode> ns = new List <IValuedNode>() { new FloatNode(null, 1), new DoubleNode(null, 2) }; IValuedNode expected = new DoubleNode(null, 3); this.TestApplication(SparqlOperatorType.Add, ns, expected, false); }
//Last — возвращает последний узел списка; public string Last() { DoubleNode <T> etot = first;//текущий int k = 0; while (k != count - 1) { etot = etot.Next; k++; } return(etot.value.ToString()); }
public int Length() { DoubleNode <T> current = _head; int result = 0; while (current != null) { result++; current = current.GetNext(); } return(result); }
public DynamoConvert() { SelectedMetricConversion = ConversionMetricUnit.Length; AssociativeNode defaultNode = new DoubleNode(0.0); InPortData.Add(new PortData("", "A numeric value for conversion.", defaultNode)); OutPortData.Add(new PortData("", "A converted numeric value.")); ShouldDisplayPreviewCore = true; IsSelectionFromBoxEnabled = true; RegisterAllPorts(); }
public DynamoConvert() { SelectedMetricConversion = ConversionMetricUnit.Length; AssociativeNode defaultNode = new DoubleNode(0.0); InPorts.Add(new PortModel(PortType.Input, this, new PortData("", Properties.Resources.UnitNodeFromPortTooltip, defaultNode))); OutPorts.Add(new PortModel(PortType.Output, this, new PortData("", Properties.Resources.UnitNodeToPortToolTip))); ShouldDisplayPreviewCore = true; IsSelectionFromBoxEnabled = true; RegisterAllPorts(); }
public void Rotate_At_2() { var list = "1 2 3 4 5 6"; var node = new DoubleNode(list); var rotatedNode = RotateDoubleLinkList.Rotate(node, 2); Assert.AreEqual(3, rotatedNode.Data); Assert.AreEqual(4, rotatedNode.Next.Data); Assert.AreEqual(5, rotatedNode.Next.Next.Data); Assert.AreEqual(6, rotatedNode.Next.Next.Next.Data); Assert.AreEqual(1, rotatedNode.Next.Next.Next.Next.Data); Assert.AreEqual(2, rotatedNode.Next.Next.Next.Next.Next.Data); }
public bool RemoveInd(int ind) { if (ind > size) { return(false); } DoubleNode curr; if (ind < size / 2) { curr = head; int i = 0; while (i != ind) { curr = curr.GetNext; i++; } } else { curr = tail; int i = size - 1; while (i != ind) { curr = curr.GetPrev; i--; } } if (curr.GetNext != null) { curr.GetNext.GetPrev = curr.GetPrev; } else { tail = curr.GetPrev; } if (curr.GetPrev != null) { curr.GetPrev.GetNext = curr.GetNext; } else { head = curr.GetNext; } size--; return(true); }
public List<string> ConvertDoubleNode(DoubleNode<StringId> doubleNode) { Contract.Requires(doubleNode != null); var firstTreeLines = GetNodeLines(doubleNode, true); var secondTreeLines = GetNodeLines(doubleNode, false); var lines = new List<string>(); for (int i = 0; i < firstTreeLines.Count; i++) { lines.Add(firstTreeLines[i] + secondTreeLines[i]); } return lines; }
private List<string> GetNodeLines(DoubleNode<StringId> doubleNode, bool isLeft) { Contract.Requires(doubleNode != null); Contract.Ensures(Contract.Result<List<string>>().Count != 0); Contract.Ensures(Contract.Result<List<string>>() != null); var nodeLines = new List<string>(); var stack = new Stack<DoubleNode<StringId>>(); stack.Push(doubleNode); var maxDepth = doubleNode.ToList().Max(node => node.Depth); while (stack.Any()) { var topElement = stack.Pop(); var space = isLeft ? new string(' ', topElement.Depth * Indent) : new string(' ', (maxDepth - topElement.Depth) * Indent); var connectionSign = ConnectionSignHelper.GetConnectionSigh(topElement.ConnectionKind); var mainId = topElement.MainLeaf.IsEmpty() ? "(" + topElement.MainLeaf.Id + ")" : topElement.MainLeaf.Id.ToString(); var minorId = topElement.MinorLeaf.IsEmpty() ? "(" + topElement.MinorLeaf.Id + ")" : topElement.MinorLeaf.Id.ToString(); var line = isLeft ? space + mainId + new string(' ', Indent) : connectionSign + new string(' ', Indent) + space + minorId; nodeLines.Add(line); var nodes = topElement.Nodes.ToList(); nodes.Reverse(); nodes.ForEach(node => stack.Push(node)); } var maxLength = nodeLines.Max(line => line.Length); nodeLines = nodeLines.Select(line => line += new String(' ', maxLength - line.Length)).ToList(); return nodeLines; }
private void DisplayTree() { Console.Clear(); var idGenerator = new IdGenerator(_bindController.MainMultiTree.ToList()); _currentDoubleNode = _treeConstructor.GetFilledTree(_bindController, idGenerator); Console.WriteLine(_consoleTreeWriter.ConvertToString(_bindController.MainMultiTree, _bindController.MinorSingleTree)); Console.WriteLine(_consoleTreeWriter.ConvertToString(_currentDoubleNode)); _treeConverter.ConvertMultiTreeAsMulti(new MultiTree<StringId>(_currentDoubleNode.ToMultiNode())).ForEach(Console.WriteLine); Console.WriteLine(); if (_messages.Any()) { Console.WriteLine(_messages.Last()); } Console.WriteLine(); }
private SwitchCase ProcessNode(DeserializerTypeContext ctx, DoubleNode node) { var bodyExpressions = new List<Expression>(); var callExtractInt = Expression.Call(null, _extractDouble, ctx.IteratorVar, ctx.StringParam); var accessMember = Expression.MakeMemberAccess(ctx.InstanceVar, node.Member); var assignMember = Expression.Assign(accessMember, callExtractInt); bodyExpressions.Add(assignMember); bodyExpressions.Add(Expression.Empty()); var body = Expression.Block(bodyExpressions); var @case = Expression.SwitchCase(body, GetSwitchConstant(ctx, node)); return @case; }
public DoubleNode(DoubleNode rhs) : base(rhs) { Value = rhs.Value; }