/// <summary>
        /// PrimeAndAnagram as a function
        /// </summary>
        public static void PrimeAndAnagram()
        {
            try
            {
                UtilityFunctions     utility = new UtilityFunctions();
                QueueUsingLinkedList queue   = new QueueUsingLinkedList();

                for (int i = 1; i <= 1000 - 1; i++)
                {
                    for (int j = i + 1; j <= 1000; j++)
                    {
                        if (utility.IsAnagram(i + string.Empty, j + string.Empty) && utility.IsPrime(i) && utility.IsPrime(j))
                        {
                            queue.Enqueue(j);
                        }
                    }
                }

                queue.Show();
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#2
0
        /// <summary>
        /// BankingCashCounterFunction as a function
        /// </summary>
        public static void BankingCashCounterFunction()
        {
            try
            {
                QueueUsingLinkedList peopleInQueue = new QueueUsingLinkedList();
                int bankBalance   = 200000;
                int withdrawLimit = 20000;
                Console.WriteLine("Enter no. of people");
                int numberOfPeople = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter names of people");
                for (int i = 0; i < numberOfPeople; i++)
                {
                    peopleInQueue.Enqueue(Console.ReadLine());
                }


                while (!peopleInQueue.IsEmpty())
                {
                    peopleInQueue.Show();
                    Console.WriteLine("Welcome to our bank " + peopleInQueue.Get());
                    Console.WriteLine("1: To withdraw money");
                    Console.WriteLine("2: To deposite money");
                    int choice = Convert.ToInt32(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine("Enter money to withdraw");
                        int amount = Convert.ToInt32(Console.ReadLine());
                        while (amount > bankBalance && amount > withdrawLimit)
                        {
                            Console.WriteLine("Withdraw limit is " + withdrawLimit);
                            amount = Convert.ToInt32(Console.ReadLine());
                        }

                        bankBalance = bankBalance - amount;
                        peopleInQueue.Dequeue();
                        break;

                    case 2:
                        Console.WriteLine("Enter cash to deposit");
                        int cash = Convert.ToInt32(Console.ReadLine());
                        while (cash < 1)
                        {
                            Console.WriteLine("Deposit amount should be atleast 1");
                            cash = Convert.ToInt32(Console.ReadLine());
                        }

                        bankBalance += cash;
                        peopleInQueue.Dequeue();
                        break;

                    default:
                        Console.WriteLine("Enter valid choice");
                        break;
                    }

                    Console.WriteLine("Bank balance " + bankBalance);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }