Пример #1
0
 public void Add(int value)
 {
     mListWithoutPrev current = new mListWithoutPrev(value);
     if (first == null)
     {
         first = current;
         last = current;
     }
     else
     {
         last.Next = current;
         var temp = last;
         last = current;
     }
     size++;
 }
Пример #2
0
 public mListWithoutPrev(int value, mListWithoutPrev res)
 {
     data = value;
     next = res;
 }
Пример #3
0
 public mListWithoutPrev()
 {
     data = 0;
     next = null;
 } 
Пример #4
0
 public void DelFirst()
 {
     first = first.Next;
     size = size - 1;
 }
Пример #5
0
 public mListWithoutPrev(int value)
 {
     data = value;
     next = null;
 }
Пример #6
0
 public void AddToStart(int value)
 {
     var temp = first;
     mListWithoutPrev current = null;
     current = new mListWithoutPrev(value);
     current.Next = temp;
     first = current;
     temp = first;
     size++;
 }
Пример #7
0
 public void Insert (int position, int value)
 {
     var temp = first;
     mListWithoutPrev current = null;
     int counter = 0;
     int k=0;
     while (temp!=null)
     {
         if (position == 0 && k == 0)
         {
             this.AddToStart(value);
             k++;
         }
         else if (position==counter)
         {
             mListWithoutPrev newElem = new mListWithoutPrev(value);
             newElem.Next = temp;
             current.Next = newElem;
             size++;
             break;
         }
         else if (counter == size-1  && position==size)
         {
             current = new mListWithoutPrev(value);
             current.Next = null;
             temp.Next = current;
             last = current;
             size++;
             break;
         }
         current = temp;
         temp = temp.Next;
         counter++;
     }
 }
Пример #8
0
 public void Delete(int position)
 {
     var temp = first;
     mListWithoutPrev current = null;
     int k = 0;
     int counter = 0;
     while (temp != null)
     {
         if (position == 0 && k==0)
         {
             this.DelFirst();
             k++;
         }
         else if (position == size-1 && position==counter)
         {
             last = current;
             last.Next = null;
             size = size - 1;
             k++;
             break;
         }
         else if (position == counter)
         {
             current.Next = temp.Next;
             temp = temp.Next;
             size = size - 1;
         }
         current = temp;
         temp = temp.Next;
         counter++;
     }
 }
Пример #9
0
        public void Clear()
        {
            mListWithoutPrev temp = first;
            mListWithoutPrev current = null;

            while (temp!=null)
            {
                current = temp;
                temp = temp.Next;
                current = null;
            }
            last = null;
            first = null;
            size=0;
        }
Пример #10
0
        public void Remove(int value)
        {
            var temp = first;
            mListWithoutPrev current = null;
            int k = 0;
            while(temp!=null)
            {
                if (temp.Data == value && temp.Data != last.Data && temp.Data != first.Data&& k==0)
                {
                    current.Next = temp.Next;
                    temp = temp.Next;
                    size = size - 1;
                    k++;
                }
                else if(temp.Data==value && temp.Data==last.Data&& k==0)
                {
                    last = current;
                    last.Next = null;
                    size = size - 1;
                    k++;
                    break;
                }
                current = temp;
                temp = temp.Next;
                if (first.Data == value&& k==0 )
                {
                    k++;
                    current = temp;
                    first = current;
                    temp = temp.Next;
                    size = size - 1;
                }
            }

         }