Example #1
0
        public CircleList(string filename)
        {
            Filename = filename;
            var file = File.ReadAllLines(filename);

            foreach (var row in file)
            {
                var splited = row.Split(' ');
                if (Temp == null)
                {
                    Temp = new Parcipiant {
                        Name = splited[0], Gender = splited[1], Next = null
                    };
                    Temp.Next = Temp;
                    Count++;
                    continue;
                }
                var par = new Parcipiant {
                    Name = splited[0], Gender = splited[1], Next = Temp.Next
                };
                Temp.Next = par;
                Temp      = Temp.Next;
                Count++;
            }
        }
Example #2
0
 private void AddOrCreate(CircleList list, Parcipiant p) //Если список пуст - создаём его, иначе добавляем эл-т
 {
     if (list.Temp == null)
     {
         p.Next    = p;
         list.Temp = p;
     }
     else
     {
         list.Insert(p);
     }
 }
Example #3
0
        public void Sort(string name)
        {
            var temp = Temp;
            var find = false;

            for (int i = 0; i < Count + 1; i++)
            {
                if (temp.Name == name)
                {
                    find = true;
                    break;
                }
                temp = temp.Next;
            }
            if (!find)
            {
                throw new ArgumentException();
            }
            var result = new CircleList();
            var par    = new Parcipiant {
                Name = temp.Name, Gender = temp.Gender
            };

            par.Next    = par;
            result.Temp = par;
            temp        = temp.Next;
            for (int i = 1; i < Count; i++)
            {
                var p = new Parcipiant {
                    Name = temp.Name, Gender = temp.Gender
                };
                var t = result.Temp;
                for (int j = 1; j < Count; j++)
                {
                    if (p.CompareTo(t.Next) < 0 || t.CompareTo(p) < 0 && t.CompareTo(t.Next) >= 0)
                    {
                        p.Next = t.Next;
                        t.Next = p;
                        break;
                    }
                    t = t.Next;
                }
                temp = temp.Next;
            }
            Temp = result.Temp;
        }
Example #4
0
        static void Main(string[] args)
        {
            var list = new CircleList("In.txt");

            list.Show();

            var p = new Parcipiant {
                Name = "qwe", Gender = "male"
            };

            list.Insert(p);

            list.Delete("qwe");

            list.Sort("Adam");

            list.Last(3);

            var genders = list.Gender();

            Console.ReadKey();
        }
Example #5
0
        public CircleList[] Gender()
        {
            var temp   = Temp;
            var male   = new CircleList();
            var female = new CircleList();

            for (int i = 0; i < Count; i++)
            {
                var par = new Parcipiant {
                    Name = temp.Name, Gender = temp.Gender
                };
                if (par.Gender == "male")
                {
                    AddOrCreate(male, par);
                }
                else
                {
                    AddOrCreate(female, par);
                }
                temp = temp.Next;
            }
            return(new CircleList[] { male, female });
        }
Example #6
0
 public void Insert(Parcipiant p) //Вставка в список на текущее место
 {
     p.Next    = Temp.Next;
     Temp.Next = p;
     Count++;
 }