public bool Delete(string s) { NodeOfList NeededNode = GetNodeOfList(s); if (NeededNode == null) { return(false); } if (NeededNode.Next == null) { Pop(); } else { if (NeededNode.Previous != null) { NeededNode.Previous.Next = NeededNode.Next; } else { _start = NeededNode.Next; } NeededNode.Next.Previous = NeededNode.Previous; _length--; } return(true); }
public NodeOfList(string info) { Previous = null; Next = null; Info = info; _sum_codes = SumOfCodes.GetSum(info); }
public string this[string s] { set { NodeOfList IndexNodeOfList = GetNodeOfList(s); if (IndexNodeOfList != null) { IndexNodeOfList.Info = value; } } }
private NodeOfList GetNodeOfList(int index) { NodeOfList slider = _start; for (int i = 1; i <= index; i++) { slider = slider.Next; } return(slider); }
public void Pop() { if (Length != 0) { NodeOfList LastNodeOfList = GetNodeOfList(_length - 1); if (_length != 1) { LastNodeOfList.Previous.Next = null; } _length--; } }
public void Push(string some_string) { if (_length == 0) { _start = new NodeOfList(some_string); _length++; } else { NodeOfList NewNodeOfList = new NodeOfList(some_string); NewNodeOfList.Previous = GetNodeOfList(_length - 1); NewNodeOfList.Previous.Next = NewNodeOfList; _length++; } }
private NodeOfList GetNodeOfList(string s) { NodeOfList slider = _start; for (int i = 1; i <= _length; i++) { if (slider.Info == s) { return(slider); } slider = slider.Next; } return(null); }
private NodeOfList GetNodeOfList(int index) { if (index < 0 || index > Length - 1) { throw new Exception("Index in list is out of range"); } NodeOfList slider = _start; for (int i = 1; i <= index; i++) { slider = slider.Next; } return(slider); }
public void Print() { Console.WriteLine("\nelements of the stack are\n\n"); NodeOfList slider = _start; if (_length == 0) { Console.WriteLine("\nthe stack is empty\n"); return; } for (int i = 0; i < Length; i++) { Console.WriteLine(slider.Info + " sum of codes is " + slider.SumCodes.ToString() + "\n"); slider = slider.Next; } Console.WriteLine("\n"); }