public void EhView_AddNormalGroupStyle() { SelectableListNode selected = null; foreach (SelectableListNode node in _availableNormalStyles) { if (node.IsSelected) { selected = node; break; } } if (null != selected) { _availableNormalStyles.Remove(selected); var s = (IPlotGroupStyle)Activator.CreateInstance((Type)selected.Tag); _doc.Add(s); var node = new MyListNode( Current.Gui.GetUserFriendlyClassName(s.GetType()), s.GetType(), true, s.IsStepEnabled, s.CanStep); if (s.CanCarryOver) { _currentNormalStyles.Insert(_currentNoOfItemsThatCanHaveChilds, node); _currentNoOfItemsThatCanHaveChilds++; } else { _currentNormalStyles.Add(node); } _view.InitializeAvailableNormalGroupStyles(_availableNormalStyles); _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles); } }
private void InitializeExistingPropertyValuesList() { var sortedNames = new List <KeyValuePair <string, string> >(); // key is the property key string, value is the property name foreach (var key in _doc.GetAllPropertyNames()) { string keyName = PropertyKeyBase.GetPropertyName(key); if (null == keyName) { keyName = key; } sortedNames.Add(new KeyValuePair <string, string>(key, keyName)); } sortedNames.Sort(((entry1, entry2) => string.Compare(entry1.Value, entry2.Value))); // sort the entries not by the key, but by the keyname _propertyList = new SelectableListNodeList(); foreach (var entry in sortedNames) { if (_doc.TryGetValue <object>(entry.Key, !_showAllProperties, out var value, out var bag, out var bagInfo)) { var node = new MyListNode(entry.Value, new Tuple <string, string, IPropertyBag>(entry.Key, entry.Value, bag)) { Text1S = value == null ? "n.a." : value.GetType().Name, Text2S = value == null ? "null" : value.ToString().Replace('\n', '_').Replace('\r', '_'), Text3S = bagInfo.Name }; _propertyList.Add(node); } } }
private void Swap(MyListNode <T> current) { var temp = current.Previous; current.Previous = current.Next; current.Next = temp; }
public PractiseLinkedList() { // create a linkedList of standard data types var x = new LinkedList <int>(); x.AddLast(10); x.AddLast(20); x.AddLast(30); var y = new LinkedList <string>(); y.AddLast("Amit"); y.AddLast("hello"); var node = new LinkedListNode <string>("Amit"); y.AddLast(node); // create a linkedList of custom object var customList = new LinkedList <MyListNode>(); var nodeObj = new MyListNode("amit", "agarwal"); customList.AddLast(nodeObj); }
protected override void Initialize(bool initData) { base.Initialize(initData); if (initData) { _propertyList = new SelectableListNodeList(); foreach (var entry in _doc) { string key = entry.Key; object value = entry.Value; var node = new MyListNode(key, key) { Text1a = value == null ? "n.a." : value.GetType().Name, Text2a = value == null ? "null" : value.ToString() }; _propertyList.Add(node); } } if (null != _view) { _view.PropertyList = _propertyList; } }
private void InitializeAvailablePropertyList() { _availablePropertyKeys = new SelectableListNodeList(); var sortedKeys = new List <Altaxo.Main.Properties.PropertyKeyBase>(Altaxo.Main.Properties.PropertyKeyBase.AllRegisteredPropertyKeys); sortedKeys.Sort((x, y) => string.Compare(x.PropertyName, y.PropertyName)); foreach (var prop in sortedKeys) { // show only the keys that are applicable to the topmost property bag in the hierarchy if (0 == (prop.ApplicationLevel & _doc.TopmostBagInformation.ApplicationLevel)) { continue; } if ((PropertyLevel.Document == (prop.ApplicationLevel & _doc.TopmostBagInformation.ApplicationLevel))) { if (!Altaxo.Main.Services.ReflectionService.IsSubClassOfOrImplements(_doc.TopmostBagInformation.ApplicationItemType, prop.ApplicationItemType)) { continue; } } var node = new MyListNode(prop.PropertyName, prop) { Text1S = prop.PropertyType.Name }; _availablePropertyKeys.Add(node); } }
public void CompareToTest() { MyListNode<int> node1 = new MyListNode<int>(10, null, null); MyListNode<int> node2 = new MyListNode<int>(20, node1, null); Assert.IsTrue(node1.CompareTo(node2) == -1); }
public void InsertAsSuccTest() { MyListNode<int> node1 = new MyListNode<int>(10, null, null); node1.InsertAsSucc(20); Assert.IsTrue(node1.Succeed.Data == 20); Assert.IsTrue(node1.Succeed.Precursor.Data == 10); }
public void InsertAsPredTest() { MyListNode<int> node1 = new MyListNode<int>(10, null, null); node1.InsertAsPred(20); Assert.IsTrue(node1.Precursor.Data == 20, "pred"); Assert.IsTrue(node1.Precursor.Succeed.Data == 10, "succ"); }
public MyList(MyList <T> myList) { Count = 0; firstNode = null; for (int i = 0; i < myList.Count; i++) { Add(myList[i]); } }
public MyList(List <T> list) { Count = 0; firstNode = null; for (int i = 0; i < list.Count; i++) { Add(list[i]); } }
public void MyListNodeTest() { MyListNode<int> node1 = new MyListNode<int>(10, null, null); MyListNode<int> node2 = new MyListNode<int>(20, node1, null); node1.Succeed = node2; Assert.IsTrue(node1.Data == 10); Assert.IsTrue(node1.Succeed.Data == 20); Assert.IsTrue(node1.Succeed.Precursor.Data == 10); }
public MyList(T[] array) { Count = 0; firstNode = null; for (int i = 0; i < array.Length; i++) { Add(array[i]); } }
public void LinkedListTest_SingleElementNoCycleReturnsFalse() { // Arrange MyLinkedList l = new MyLinkedList(); MyListNode head = new MyListNode(1); // Act bool result = l.HasCycle(head); // Assert Assert.IsFalse(result); }
public void AddFirst(T item) { MyListNode node = new MyListNode(item); node.next = first; first = node; if (last == null) { last = node; } count += 1; }
public void AddAfter(T item, MyListNode after) { MyListNode node = new MyListNode(item); node.next = after.next; after.next = node; if (last == after) { last = node; } count += 1; }
public void AddLast(T item) { MyListNode node = new MyListNode(item); if (first == null) { first = node; } if (last != null) { last.next = node; } last = node; count += 1; }
public void LinkedListTest_TwoElementNoCycleReturnsFalse() { // Arrange MyLinkedList l = new MyLinkedList(); MyListNode head = new MyListNode(1); MyListNode value2 = new MyListNode(2); head.next = value2; // Act bool result = l.HasCycle(head); // Assert Assert.IsFalse(result); }
//private MyNode[] labyrinth; public static void Main() { var input = new string[,] {{"0","0","0","x","0","x"}, {"0","x","0","x","0","x"}, {"0","*","x","0","x","0"}, {"0","x","0","0","0","0"}, {"0","0","0","x","x","0"}, {"0","0","0","x","0","x"}}; var row = 2; var col = 1; var head = new MyListNode<string>(input[row, col]); var some = new LinkedList<MyListNode<string>>(new []{head}); some. while (true) { // може ли в ляво if (col - 1 >= 0) { } // може ли нагоре if (row - 1 >= 0) { } // може ли в дясно if (col + 1 < Columns) { } // може ли надолу if (row + 1 < Rows) { } } Print(input); }
private MyListNode <T> GetItem(int index) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(); } MyListNode <T> toReturn = firstNode; while (index > 0) { toReturn = toReturn.Next; index--; } return(toReturn); }
public void Insert(int index, T value) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(); } MyListNode <T> toInsert = new MyListNode <T>(value); var originalPosItem = GetItem(index); toInsert.Previous = originalPosItem.Previous; toInsert.Next = originalPosItem; originalPosItem.Previous.Next = toInsert; originalPosItem.Previous = toInsert; Count++; }
public void LinkedListTest_LastElementsNextIsMiddleReturnsTrue() { // Arrange MyLinkedList l = new MyLinkedList(); MyListNode head = new MyListNode(1); MyListNode value2 = new MyListNode(2); MyListNode value3 = new MyListNode(3); MyListNode value4 = new MyListNode(4); head.next = value2; value2.next = value3; value3.next = value4; value4.next = value3; // Act bool result = l.HasCycle(head); // Assert Assert.IsTrue(result); }
public void RemoveAt(int index) { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException(); } MyListNode <T> toRemove = firstNode; while (index > 0) { toRemove = toRemove.Next; index--; } toRemove.Previous.Next = toRemove.Next; toRemove.Next.Previous = toRemove.Previous; Count--; }
public void Reverse() { if (Count <= 1) { return; } MyListNode <T> toOperate = firstNode; Swap(firstNode); toOperate = firstNode.Previous; while (toOperate != firstNode) { Swap(toOperate); toOperate = toOperate.Previous; } firstNode = firstNode.Next; }
public void Add(T item) { if (firstNode == null) { firstNode = new MyListNode <T>(item); firstNode.Previous = firstNode; firstNode.Next = firstNode; } else { MyListNode <T> newNode = new MyListNode <T>(item); newNode.Next = firstNode; newNode.Previous = firstNode.Previous; firstNode.Previous = newNode; newNode.Previous.Next = newNode; } Count++; }
protected override void Initialize(bool initData) { base.Initialize(initData); if (initData) { // available Update modes _availableUpdateModes = new SelectableListNodeList(); foreach (object obj in Enum.GetValues(typeof(PlotGroupStrictness))) { _availableUpdateModes.Add(new SelectableListNode(obj.ToString(), obj, ((PlotGroupStrictness)obj) == PlotGroupStrictness.Normal)); } Type[] types; // Transfo-Styles _currentTransfoStyle = _doc.CoordinateTransformingStyle == null ? null : (ICoordinateTransformingGroupStyle)_doc.CoordinateTransformingStyle.Clone(); _availableTransfoStyles = new SelectableListNodeList { new SelectableListNode("None", null, null == _currentTransfoStyle) }; types = ReflectionService.GetNonAbstractSubclassesOf(typeof(ICoordinateTransformingGroupStyle)); foreach (Type t in types) { Type currentStyleType = _currentTransfoStyle == null ? null : _currentTransfoStyle.GetType(); ICoordinateTransformingGroupStyle style; if (t == currentStyleType) { style = _currentTransfoStyle; } else { style = (ICoordinateTransformingGroupStyle)Activator.CreateInstance(t); } _availableTransfoStyles.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(t), style, t == currentStyleType)); } // Normal Styles _availableNormalStyles = new SelectableListNodeList(); if (_parent != null) // if possible, collect only those styles that are applicable { var avstyles = new PlotGroupStyleCollection(); _parent.CollectStyles(avstyles); foreach (IPlotGroupStyle style in avstyles) { if (!_doc.ContainsType(style.GetType())) { _availableNormalStyles.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(style.GetType()), style.GetType(), false)); } } } else // or else, find all available styles { types = ReflectionService.GetNonAbstractSubclassesOf(typeof(IPlotGroupStyle)); foreach (Type t in types) { if (!_doc.ContainsType(t)) { _availableNormalStyles.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(t), t, false)); } } } var list = _doc.GetOrderedListOfItems(ComparePlotGroupStyles); _currentNormalStyles = new CheckableSelectableListNodeList(); _currentNoOfItemsThatCanHaveChilds = 0; foreach (var item in list) { if (item.CanCarryOver) { ++_currentNoOfItemsThatCanHaveChilds; } var node = new MyListNode(Current.Gui.GetUserFriendlyClassName(item.GetType()), item.GetType(), false, item.IsStepEnabled, item.CanStep); _currentNormalStyles.Add(node); } UpdateCurrentNormalIndentation(); } if (_view != null) { _view.InitializeAvailableCoordinateTransformingGroupStyles(_availableTransfoStyles); _view.InitializeAvailableNormalGroupStyles(_availableNormalStyles); _view.InitializeCurrentNormalGroupStyles(_currentNormalStyles); _view.InitializeUpdateMode(_availableUpdateModes, _doc.InheritFromParentGroups, _doc.DistributeToChildGroups); } }
public MyList() { Count = 0; firstNode = null; }
public MyListNode(T2 item) { Previous = null; Next = null; Data = item; }
public void Clear() { firstNode = null; Count = 0; }