using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace laba6._3 { public class Node { public T Data { get; set; } public Node(T data) { Data = data; } public Node Next { get; set; } } public class LinkedList { public Node head; // головной/первый элемент Node tail; // последний/хвостовой элемент //pnext int count; // количество элементов в списке // добавление элемента public int s() { return count; } public void Add(T data) { Node node = new Node(data); if (head == null) head = node; else tail.Next = node; tail = node; count++; } public void Show() { Node temp = this.head; while(temp.Next!=null) { temp = temp.Next; Console.WriteLine(temp.Data); } } public static LinkedList operator -- (LinkedList a) { Node previos = a.head; int k; k = a.count; for (int i = 0; i < (k-1)-1; i++) { previos = previos.Next; } Node toDelete = previos.Next; previos.Next = toDelete.Next; toDelete=null; return a; } public static LinkedList operator + (LinkedList a, T k) { if (a.head==null) { a.head = new Node(k); } Node current = a.head; while(current.Next!=null) { current = current.Next; } current.Next = new Node(k); return a; } public static LinkedList operator + (LinkedList a, LinkedList a2) { Node current = a.head; Node temp = a2.head; while (current.Next != null) current = current.Next; current.Next = new Node(a2.head.Data); current = current.Next; while(temp.Next!=null) { current.Next = new Node(temp.Next.Data); temp = temp.Next; current = current.Next; } return a; } public static LinkedList operator ~ (LinkedList a) { int counter = 0; // int index, index1; //Console.WriteLine("Введите числа"); //index = int.Parse(Console.ReadLine()); //index1 = int.Parse(Console.ReadLine()); LinkedList rez = new LinkedList(); Node temp = a.head; while(temp!=null) { if (counter>=1 && counter<=2) { rez = rez + temp.Data; } temp = temp.Next; counter++; } return rez; } public static bool operator != (LinkedList a, LinkedList a1) { if (a.count != a1.count) return true; else return false; } public static bool operator ==(LinkedList a, LinkedList a1) { if (a.count == a1.count) return true; else return false; } public static bool operator < (LinkedList a, LinkedList a1) { if (a.count < a1.count) return true; else return false; } public static bool operator > (LinkedList a, LinkedList a1) { if (a.count > a1.count) return true; else return false; } public static bool operator >=(LinkedList a, LinkedList a1) { if (a.count >= a1.count) return true; else return false; } public static bool operator <=(LinkedList a, LinkedList a1) { if (a.count <= a1.count) return true; else return false; } public static LinkedList operator - (LinkedList a, T data) { // a.tail.Data Node current = a.head; Node previous = null; while (current != null) { if (current.Data.Equals(data)) { if (previous != null) { previous.Next = current.Next; if (current.Next == null) a.tail = previous; } else { a.head = a.head.Next; if (a.head == null) a.tail = null; } } previous = current; current = current.Next; } return a; } } class Program { static void Main(string[] args) { LinkedList My = new LinkedList(); LinkedList My1 = new LinkedList(); LinkedList My3 = new LinkedList(); My.Add(1); My.Add(6); My.Add(7); My.Add(8); My.Add(9); My.Add(10); My.Add(5); My--; My--; My.Show(); //My1.Add(6); //My1.Add(7); //My3 = ~My; //My3.Show(); // if (My != My1) Console.WriteLine("Списки не равны!"); //else Console.WriteLine("Списки равны!"); //Console.WriteLine(~My);- Console.ReadKey(); } } }