Beispiel #1
0
 public void Print()
 {
     for (RList i = this.next; i != null; i = i.next)
     {
         Console.Write(i.key + " ");
     }
     Console.WriteLine();
 }
Beispiel #2
0
 public static RList operator *(RList rl, int a)
 {
     for (RList i = rl; i != null; i = i.next)
     {
         i.key *= a;
     }
     return(rl);
 }
Beispiel #3
0
 public void PrintOdd()
 {
     for (RList i = this.next; i != null; i = i.next)
     {
         if (i.key % 2 != 0)
         {
             Console.Write(i.key + " ");
         }
     }
 }
Beispiel #4
0
 public void Add(int n)
 {
     if (this.next != null)
     {
         this.next.Add(n);
     }
     else
     {
         this.next = new RList(n);
     }
 }
Beispiel #5
0
 public int Search(int n)
 {
     for (RList i = this.next; i != null; i = i.next)
     {
         if (i.key == n)
         {
             return(this.Length - i.Length);
         }
     }
     return(-1);
 }
Beispiel #6
0
 public void Insert(int m, int n)
 {
     for (RList i = this.next; i != null; i = i.next)
     {
         if (i.key == n)
         {
             RList t = i.next;
             i.next      = new RList(m);
             i.next.next = t;
             return;
         }
     }
 }
Beispiel #7
0
        public static int operator +(RList rl1, RList rl2)
        {
            int res = 0;

            for (RList i = rl1; i != null; i = i.next)
            {
                res += i.key;
            }
            for (RList i = rl2; i != null; i = i.next)
            {
                res += i.key;
            }
            return(res);
        }
Beispiel #8
0
 public void Delete()
 {
     if (this.next != null)
     {
         if (this.next.next != null)
         {
             this.next.Delete();
         }
         else
         {
             this.next = null;
         }
     }
     else
     {
         Console.Write("Список пуст!");
     }
 }
Beispiel #9
0
 public void DeleteNum(int n)
 {
     if (n < 0 || n > Length)
     {
         Console.WriteLine("Элемент не существует!");
     }
     else
     {
         if (n != 1)
         {
             this.next.DeleteNum(--n);
         }
         else
         {
             RList t = this.next.next;
             this.next = t;
         }
     }
 }
Beispiel #10
0
        public static void Main()
        {
            //#20
            RList rl = new RList(0);

            rl.Add(70);
            rl.Add(10);
            rl.Add(70);
            rl.Add(30);
            rl.Add(70);
            //rl.Print();
            //rl.Length = 3;
            //Console.WriteLine(rl.Length);
            //rl.Print();
            //RList r2 = new RList(0);
            //r2.Add(10);
            //Console.WriteLine(rl + r2);
            //Console.WriteLine(rl.Search(70));
            //rl.DeleteNum(200);
            rl.DeleteElements(75);
            rl.Print();
        }
Beispiel #11
0
 public void DeleteElements(int n)
 {
     if (next != null)
     {
         if (next.key == n)
         {
             if (next.next != null)
             {
                 next = next.next;
                 next.DeleteElements(n);
             }
             else
             {
                 Delete();
             }
         }
         else
         {
             next.DeleteElements(n);
         }
     }
 }
Beispiel #12
0
 public RList(RList rl)
 {
     key  = rl.key;
     next = rl.next;
 }
Beispiel #13
0
 public RList(int n)
 {
     key  = n;
     next = null;
 }