public override TimeSpan GetNElement(int N)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     Gift gift = new Gift();
     gift = myStack.ToArray()[N-1];
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
 public override TimeSpan RemoveNElement(int N)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     Gift gift = new Gift();
     myHashtable.Remove(N);
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
 public override TimeSpan GetNElement(int N)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     Gift gift = new Gift();
     myDictionary.TryGetValue(N, out gift);
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
 public override TimeSpan Init(Gift gift)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     for (int i = 1; i <= 1000; i++)
     {
         myHashtable.Add(i, gift);
     }
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
 public override TimeSpan Init(Gift gift)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     for (int i = 1; i <= 1000; i++)
     {
         myQueue.Enqueue(gift);
     }
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed; 
     return timeSpan;
 }
 public override TimeSpan Init(Gift gift)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     for (int i = 0; i <= 1000; i++)
     {
         myArrayList.Add(gift);
     }
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     
     return timeSpan;
 }
 public override TimeSpan Init(Gift gift)
 {
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     myLinkedList.AddFirst(gift);
     for (int i = 1; i <= 1000; i++)
     {
         myLinkedList.AddLast(gift);
     }
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
 public override TimeSpan GetNElement(int N)
 {
     int i = 1;
     Stopwatch sWatch = new Stopwatch();
     sWatch.Start();
     Gift gift = new Gift();
     foreach (DictionaryEntry key in myHashtable)
     {
         if (i == N)
         {
             gift = (Gift) key.Value;
             break;
         }
         i++;
     }
     sWatch.Stop();
     TimeSpan timeSpan = sWatch.Elapsed;
     return timeSpan;
 }
        public override TimeSpan RemoveNElement(int N)
        {
            Stopwatch sWatch = new Stopwatch();

            Gift gift = new Gift();
            Stack<Gift> tmpStack = new Stack<Gift>();
            sWatch.Start();
            int count = myStack.Count - N;

            for (int i = 0; i < count; i++)
            {
                tmpStack.Push(myStack.Pop()); 
            }
            tmpStack.Pop();
            count = tmpStack.Count;
            for (int i = 0; i < count; i++)
            {
                tmpStack.Push(tmpStack.Pop());
            }
            myStack.Pop();
            sWatch.Stop();
            TimeSpan timeSpan = sWatch.Elapsed;
            return timeSpan;
        }
 public abstract TimeSpan Init(Gift gift);
 public static Gift PackGift()
 {
     Gift gift = new Gift();
     gift.AddSweet(new ChocolateCandyWithJelly("Blackberry", 10, 24.01));
     gift.AddSweet(new ChocolateCandyWithCream("Noir", 15, 30.4));
     gift.AddSweet(new ChocolateCandyWithNuts("ChocoNuts", 9, 10.5));
     gift.AddSweet(new ChocolateCandyTruffle("Truffle", 15.1, 15));
     gift.AddSweet(new IrisCream("Iris Cream", 20, 30.02));
     gift.AddSweet(new IrisForChildren("Child's Iris", 23, 15.03));
     gift.AddSweet(new IrisWithFilling("Iriska", "milky cream", 32, 10.22));
     gift.AddSweet(new CaramelMedical("Halls", 35, 14.20));
     gift.AddSweet(new CaramelInChocolate("ChocoShock", 15, 20.11));
     gift.AddSweet(new LollipopFruitty("Fruitty", 22, 32.01));
     gift.AddSweet(new LollipopMilky("Milky lollipop", 12, 40.00));
     gift.AddSweet(new LollipopMinty("Minty lollipop", 21, 22.00));
     gift.AddSweet(new LollipopWithFilling("Cherry lollopop", "Cherry", 34, 28.04));
     gift.AddSweet(new JellyBean("JellyBean", 33, 20.62));
     gift.AddSweet(new Milky("Milky Candy", 27, 42.02));
     gift.AddSweet(new Roasting("Grilyazh", 52, 34.05));
     gift.AddSweet(new WaffleCandy("Waffle candy", 28, 33.44));
     return gift;
 }
        static void Main(string[] args)
        {
         #region Part1
            Gift gift = new Gift();
            gift = PackGift();
            Console.WriteLine("List of sweets in the gift:");
            Console.WriteLine("");
            gift.ShowGiftList();
            Console.WriteLine("========================================================================");

            Console.WriteLine();
            Console.WriteLine("Gift weight is {0}", gift.Weight);
            Console.WriteLine();

            Console.WriteLine("========================================================================");
            Console.WriteLine("");
            Console.WriteLine("Press Enter to sort by price");
            const char chchoise = '1';
            Console.ReadLine();
            Console.WriteLine("");
            Console.WriteLine("========================================================================");
            gift.SortBy(chchoise); // no logic but to show polymorphism
            gift.ShowGiftList();

            Console.WriteLine("========================================================================");
            Console.WriteLine("");
            Console.WriteLine("Press Enter to sort by weight");
            const int ichoice = 1;
            Console.ReadLine();
            Console.WriteLine("");
            Console.WriteLine("========================================================================");
            gift.SortBy(ichoice); // no logic but to show polymorphism
            gift.ShowGiftList();

            Console.WriteLine("========================================================================");
            Console.WriteLine("");
            Console.WriteLine("Enter search conditions:");

            bool flag = false;
            bool flag2 = false;

            do
            {
                Console.WriteLine("Weight more than:");
                try
                {
                    double from = Convert.ToDouble(Console.ReadLine());
                    flag = true;
                    do
                    {
                        Console.WriteLine("Weight less than:");
                        try
                        {
                            double to = Convert.ToDouble(Console.ReadLine());
                            gift.FindByWeight(from, to);
                            flag2 = true;
                            break;
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("You entered incorrect value:");
                        }

                    } while (flag2 == false);
                }
                catch (Exception)
                {
                    Console.WriteLine("You entered incorrect value:");
                }
            } while (flag == false);

            Console.WriteLine("========================================================================");
            Console.WriteLine("");
            Console.WriteLine("Press Enter to continue with part 2");
            Console.ReadLine();
            
           #endregion

            #region Part 2

            #region ArrayList vs LinkedList
            MyArrayList myArrayList = new MyArrayList();
            MyLinkedList myLinkedList = new MyLinkedList();
            CompareObjects(myArrayList, myLinkedList);
            Console.WriteLine("Press Enter to continue");
            Console.ReadLine();
            #endregion

            #region Stack vs Queue
            MyQueue myQueue = new MyQueue();
            MyStack myStack = new MyStack();
            CompareObjects(myQueue, myStack);
            Console.WriteLine("Press Enter to continue");
            Console.ReadLine();
            #endregion

            #region HashTable vs Dictionary
            MyHashTable myHashTable = new MyHashTable();
            MyDictionary myDictionary = new MyDictionary();
            CompareObjects(myHashTable, myDictionary);
            #endregion
            #endregion

            
            Console.WriteLine("");
            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();

        }