Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 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 _2018_12_07_GenerickySeznam.Model
  8. {
  9. class GenerickySeznam<T>:IEnumerable<T>
  10. {
  11. Node<T> zac = null, kon = null;
  12.  
  13. public void VlozNaPozici(T vstup, int kam)
  14. {
  15.  
  16. }
  17.  
  18. public bool OdeberHodnotu(T co)
  19. {
  20. return true;
  21. }
  22.  
  23. public void Vloz(T vstup)
  24. {
  25. Node<T> novy = new Node<T>(vstup);
  26.  
  27. if (zac == null)
  28. {
  29. kon = zac = novy;
  30. }
  31. kon.dalsi = novy;
  32. novy.dalsi = null;
  33. kon = novy;
  34. }
  35.  
  36. public T Odeber()
  37. {
  38.  
  39. T docasny = zac.hodnota;
  40. zac = zac.dalsi;
  41. if (zac == null) kon = null;
  42. return docasny;
  43.  
  44. }
  45.  
  46. public static GenerickySeznam<T> operator +(GenerickySeznam<T> prvni, GenerickySeznam<T> druhy)
  47. {
  48. GenerickySeznam<T> novy = new GenerickySeznam<T>();
  49.  
  50. //vytvoříme nový seznam, do kterého zkopírujeme prvni a druhy
  51.  
  52. return novy;
  53. }
  54.  
  55. public static GenerickySeznam<T> operator +(GenerickySeznam<T> prvni, T druhy)
  56. {
  57. GenerickySeznam<T> novy = new GenerickySeznam<T>();
  58.  
  59. //vytvoříme kopii existujícího seznamu (prvni) a vlozime do nej druhy
  60.  
  61. return novy;
  62. }
  63.  
  64. public IEnumerator<T> GetEnumerator()
  65. {
  66. var node = zac;
  67. while (node != null)
  68. {
  69. yield return node.hodnota;
  70. node = node.dalsi;
  71. }
  72. }
  73.  
  74. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  75. {
  76. return GetEnumerator();
  77. }
  78.  
  79. internal class Node<T>
  80. {
  81. public T hodnota;
  82. public Node<T> dalsi;
  83.  
  84. public Node(T hodn)
  85. {
  86. hodnota = hodn;
  87. }
  88. }
  89.  
  90.  
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement