Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 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 ConsoleApp1
  8. {
  9. public sealed class ScientistsList
  10. {
  11. private NodeScientist head; // Start of list
  12. private NodeScientist tail; // End of list
  13. private NodeScientist link; // List link to other node
  14.  
  15. public ScientistsList()
  16. {
  17. head = null;
  18. tail = null;
  19. link = null;
  20. }
  21.  
  22. public void Remove()
  23. {
  24. while (head != null)
  25. {
  26. link = head;
  27. head = head.Link;
  28. link.Link = null;
  29. }
  30. tail = link = head;
  31. }
  32.  
  33. public void GetHead(Scientist newScientist)
  34. {
  35. head = new NodeScientist(newScientist, head);
  36. }
  37.  
  38. public void SetData(Scientist newScientist)
  39. {
  40. var temp = new NodeScientist(newScientist, null);
  41. if(head != null)
  42. {
  43. tail.Link = temp;
  44. tail = temp;
  45. }
  46. else
  47. {
  48. head = temp;
  49. tail = temp;
  50. }
  51. }
  52.  
  53. public void Sort()
  54. {
  55. for(NodeScientist i = head.Link; i.Link != null; i = i.Link)
  56. {
  57. NodeScientist max = i;
  58. for(NodeScientist j = i.Link; j.Link != null; j = j.Link)
  59. {
  60. if (j.Data < max.Data)
  61. {
  62. max = j;
  63. }
  64. }
  65. Scientist temp = i.Data;
  66. i.Data = max.Data;
  67. max.Data = temp;
  68. }
  69. }
  70.  
  71.  
  72. public void Start() { link = head; }
  73. public void Next() { link = link.Link; }
  74. public bool Exists() { return link != null; }
  75. public void Finish() { link = tail; }
  76. public Scientist GetData() { return link.Data; }
  77.  
  78. public bool Contains(Scientist scientist)
  79. {
  80. bool temp = false;
  81. for(NodeScientist i = head; i != null; i = i.Link)
  82. {
  83. if (i.Data.Equals(scientist))
  84. temp = true;
  85. }
  86. return temp;
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement