Пример #1
0
 //Task 1
 private static void Show(CircularList list)
 {
     for (int i = 0; i < list.Capacity; i++)
     {
         Console.WriteLine(i+". "+list.Get(i));
     }
     Console.WriteLine();
 }
Пример #2
0
        //Task 3
        private static int Search(CircularList list, int key)
        {
            int index = -1;
            for (int i = 0; i < list.Capacity; i++)
            {
                if (list.Get(i) == key) return i;
            }

            return index;
        }
Пример #3
0
 //Task 5
 private static void SantaBarbara(CircularList list, int SearchKey, int ElementToAdd)
 {
     int index = Search(list, SearchKey);
     if (index == -1) list.Add(ElementToAdd);
     else list.Add(ElementToAdd, index + 1);
 }
Пример #4
0
        static void Main(string[] args)
        {
            //Creating list
            CircularList list = new CircularList();
            FillWithRandom(list, 10);

            //Running task functions
            Show(list);
            AddThree(new int[] { 1, 1, 1 }, list);
            Show(list);

            Console.WriteLine("Enter key to search: ");
            int keyToSearch = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Search result: " + Search(list, keyToSearch));
            Console.WriteLine();

            SantaBarbara(list, 1, 9);
            Show(list);

            Console.ReadLine();
        }
Пример #5
0
 // Helper function
 private static void FillWithRandom(CircularList list, int numberOfElements)
 {
     Random rand = new Random();
     for (int i = 0; i < numberOfElements; i++)
     {
         list.Add(rand.Next(), i);
     }
 }
Пример #6
0
 //Task 6
 private static void AddThree(int[] a, CircularList list)
 {
     for (int i = a.Length-1; i >= 0; i--)
     {
         list.Add(a[i], 3);
     }
 }