public CircleList[] Gender()
        {
            var current = new CircleList[2];
            var list    = this.Head;
            var root    = list;

            while (root.Next != list)
            {
                if (root.Data.Gender == "man")
                {
                    current[0].Insert(root.Data);
                }
                else
                {
                    current[1].Insert(root.Data);
                }
                root = root.Next;
            }
            if (this.Tail.Data.Gender == "man")
            {
                current[0].Insert(this.Tail.Data);
            }
            else
            {
                current[1].Insert(this.Tail.Data);
            }
            return(current);
        }
        public CircleList Sort()
        {
            var list    = this.Head;
            int count   = this.Count();
            var arr     = new Participant[count];
            var current = list;
            int k       = 0;

            while (current.Next != list)
            {
                arr[k] = current.Data;
                k++;
                current = current.Next;
            }
            arr[count - 1] = this.Tail.Data;
            for (int i = 0; i < count; i++)
            {
                for (int j = i + 1; j < count; j++)
                {
                    if (String.Compare(arr[i].Name, arr[j].Name) > 0)
                    {
                        Participant a = arr[i];
                        arr[i] = arr[j];
                        arr[j] = a;
                    }
                }
            }
            CircleList sortList = new CircleList();

            for (int b = 0; b < count; b++)
            {
                sortList.Insert(arr[b]);
            }
            return(sortList);
        }
Exemplo n.º 3
0
        public void TestForSort()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };
            Participant participant4 = new Participant {
                Name = "Sarah", Gender = "woman"
            };

            list.Insert(participant1);
            list.Insert(participant2);
            list.Insert(participant3);
            list.Insert(participant4);
            var sortList = new CircleList();

            sortList = list.Sort();
            Assert.AreEqual("Jessica", sortList.Head.Data.Name);
            Assert.AreEqual("John", sortList.Head.Next.Data.Name);
            Assert.AreEqual("Mark", sortList.Head.Next.Next.Data.Name);
            Assert.AreEqual("Sarah", sortList.Tail.Data.Name);
        }
Exemplo n.º 4
0
        public void TestForGender()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };
            Participant participant4 = new Participant {
                Name = "Sarah", Gender = "woman"
            };

            list.Insert(participant1);
            list.Insert(participant2);
            list.Insert(participant3);
            list.Insert(participant4);
            var current = new CircleList[2];

            current = list.Gender();
            Assert.AreEqual(2, current[0].Count());
            Assert.AreEqual(2, current[1].Count());
            Assert.AreEqual("man", current[0].Head.Data.Gender);
            Assert.AreEqual("Sarah", current[1].Tail.Data.Name);
        }
Exemplo n.º 5
0
        public void TestForInsert()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };

            list.Insert(participant1);
            list.Insert(participant2);
            list.Insert(participant3);
            Assert.AreEqual(3, list.Count());
        }
Exemplo n.º 6
0
        public void TestForShow()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };

            list.Show();
            Assert.AreEqual(3, list.Count());
            Assert.AreEqual("John", list.Head.Data.Name);
            Assert.AreEqual("man", list.Tail.Data.Gender);
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };

            CircleList list = new CircleList();

            list.Head.Data = participant1;
            list.Head.Next = new ListItem {
                Data = participant2
            };
            list.Tail = new ListItem {
                Data = participant3, Next = list.Head
            };

            list.Show();

            Participant participant4 = new Participant {
                Name = "Sarah", Gender = "woman"
            };

            list.Insert(participant4);

            list.Delete("Jessica");

            Console.WriteLine(list.ParticipantLast(2));

            Console.WriteLine(list.Gender());

            Console.WriteLine(list.Sort());
        }
Exemplo n.º 8
0
        public void TestForDelete()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };
            Participant participant4 = new Participant {
                Name = "Sarah", Gender = "woman"
            };

            list.Insert(participant1);
            list.Insert(participant2);
            list.Insert(participant3);
            list.Delete("Jessica");
            Assert.AreEqual(2, list.Count());
            Assert.AreEqual(false, list.Contains(participant2));
        }
Exemplo n.º 9
0
        public void TestForParticipantLast()
        {
            var         list         = new CircleList();
            Participant participant1 = new Participant {
                Name = "John", Gender = "man"
            };
            Participant participant2 = new Participant {
                Name = "Jessica", Gender = "woman"
            };
            Participant participant3 = new Participant {
                Name = "Mark", Gender = "man"
            };
            Participant participant4 = new Participant {
                Name = "Sarah", Gender = "woman"
            };

            list.Insert(participant1);
            list.Insert(participant2);
            list.Insert(participant3);
            list.Insert(participant4);
            list.ParticipantLast(2);
            Assert.AreEqual("Sarah", list.Tail.Data.Name);
            Assert.AreEqual("woman", list.Tail.Data.Gender);
        }