public void Print() { for (RList i = this.next; i != null; i = i.next) { Console.Write(i.key + " "); } Console.WriteLine(); }
public static RList operator *(RList rl, int a) { for (RList i = rl; i != null; i = i.next) { i.key *= a; } return(rl); }
public void PrintOdd() { for (RList i = this.next; i != null; i = i.next) { if (i.key % 2 != 0) { Console.Write(i.key + " "); } } }
public void Add(int n) { if (this.next != null) { this.next.Add(n); } else { this.next = new RList(n); } }
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); }
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; } } }
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); }
public void Delete() { if (this.next != null) { if (this.next.next != null) { this.next.Delete(); } else { this.next = null; } } else { Console.Write("Список пуст!"); } }
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; } } }
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(); }
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); } } }
public RList(RList rl) { key = rl.key; next = rl.next; }
public RList(int n) { key = n; next = null; }