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 ConsoleApp1
- {
- public sealed class ScientistsList
- {
- private NodeScientist head; // Start of list
- private NodeScientist tail; // End of list
- private NodeScientist link; // List link to other node
- public ScientistsList()
- {
- head = null;
- tail = null;
- link = null;
- }
- public void Remove()
- {
- while (head != null)
- {
- link = head;
- head = head.Link;
- link.Link = null;
- }
- tail = link = head;
- }
- public void GetHead(Scientist newScientist)
- {
- head = new NodeScientist(newScientist, head);
- }
- public void SetData(Scientist newScientist)
- {
- var temp = new NodeScientist(newScientist, null);
- if(head != null)
- {
- tail.Link = temp;
- tail = temp;
- }
- else
- {
- head = temp;
- tail = temp;
- }
- }
- public void Sort()
- {
- for(NodeScientist i = head.Link; i.Link != null; i = i.Link)
- {
- NodeScientist max = i;
- for(NodeScientist j = i.Link; j.Link != null; j = j.Link)
- {
- if (j.Data < max.Data)
- {
- max = j;
- }
- }
- Scientist temp = i.Data;
- i.Data = max.Data;
- max.Data = temp;
- }
- }
- public void Start() { link = head; }
- public void Next() { link = link.Link; }
- public bool Exists() { return link != null; }
- public void Finish() { link = tail; }
- public Scientist GetData() { return link.Data; }
- public bool Contains(Scientist scientist)
- {
- bool temp = false;
- for(NodeScientist i = head; i != null; i = i.Link)
- {
- if (i.Data.Equals(scientist))
- temp = true;
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement