示例#1
0
 private void AddOrCreate(CircleList list, Parcipiant p) //Если список пуст - создаём его, иначе добавляем эл-т
 {
     if (list.Temp == null)
     {
         p.Next    = p;
         list.Temp = p;
     }
     else
     {
         list.Insert(p);
     }
 }
示例#2
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;
        }
示例#3
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();
        }
示例#4
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 });
        }