Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace practice9
  8. {
  9. public class CircleList<T>
  10. {
  11.  
  12. Node<T> head; // головной/первый элемент
  13. Node<T> tail; // последний/хвостовой элемент
  14. int count; // количество элементов в списке
  15.  
  16. // добавление элемента
  17. public void Add(T data)
  18. {
  19. Node<T> node = new Node<T>(data);
  20. // если список пуст
  21. if (head == null)
  22. {
  23. head = node;
  24. tail = node;
  25. tail.Next = head;
  26. }
  27. else
  28. {
  29. node.Next = head;
  30. tail.Next = node;
  31. tail = node;
  32. }
  33. count++;
  34. }
  35.  
  36.  
  37.  
  38. public int Count { get { return count; } }
  39. public bool IsEmpty { get { return count == 0; } }
  40.  
  41. public void Clear()
  42. {
  43. head = null;
  44. tail = null;
  45. count = 0;
  46. }
  47.  
  48. public bool Contains(T data)
  49. {
  50. Node<T> current = head;
  51. if (current == null) return false;
  52. do
  53. {
  54. if (current.Data.Equals(data))
  55. return true;
  56. current = current.Next;
  57. }
  58. while (current != head);
  59. return false;
  60. }
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67. public class Node<T>
  68. {
  69.  
  70.  
  71. public Node(T data)
  72. {
  73. Data = data;
  74. }
  75. public T Data { get; set; }
  76. public Node<T> Next { get; set; }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement