Пример #1
0
        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);
        }
Пример #2
0
 public NodeOfList(string info)
 {
     Previous   = null;
     Next       = null;
     Info       = info;
     _sum_codes = SumOfCodes.GetSum(info);
 }
Пример #3
0
 public string this[string s]
 {
     set
     {
         NodeOfList IndexNodeOfList = GetNodeOfList(s);
         if (IndexNodeOfList != null)
         {
             IndexNodeOfList.Info = value;
         }
     }
 }
Пример #4
0
        private NodeOfList GetNodeOfList(int index)
        {
            NodeOfList slider = _start;

            for (int i = 1; i <= index; i++)
            {
                slider = slider.Next;
            }

            return(slider);
        }
Пример #5
0
 public void Pop()
 {
     if (Length != 0)
     {
         NodeOfList LastNodeOfList = GetNodeOfList(_length - 1);
         if (_length != 1)
         {
             LastNodeOfList.Previous.Next = null;
         }
         _length--;
     }
 }
Пример #6
0
 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++;
     }
 }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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");
        }