Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace practice9
- {
- public class CircleList<T>
- {
- Node<T> head; // головной/первый элемент
- Node<T> tail; // последний/хвостовой элемент
- int count; // количество элементов в списке
- // добавление элемента
- public void Add(T data)
- {
- Node<T> node = new Node<T>(data);
- // если список пуст
- if (head == null)
- {
- head = node;
- tail = node;
- tail.Next = head;
- }
- else
- {
- node.Next = head;
- tail.Next = node;
- tail = node;
- }
- count++;
- }
- public int Count { get { return count; } }
- public bool IsEmpty { get { return count == 0; } }
- public void Clear()
- {
- head = null;
- tail = null;
- count = 0;
- }
- public bool Contains(T data)
- {
- Node<T> current = head;
- if (current == null) return false;
- do
- {
- if (current.Data.Equals(data))
- return true;
- current = current.Next;
- }
- while (current != head);
- return false;
- }
- }
- public class Node<T>
- {
- public Node(T data)
- {
- Data = data;
- }
- public T Data { get; set; }
- public Node<T> Next { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement