Exemplo n.º 1
0
        /// <summary>
        /// the add and moving the file
        /// </summary>
        public void AddAndRemoveFile()
        {
            //// creating the utility object class
            Utility utility = new Utility();
            //// creating the linked list object
            LinkedListClass     ll1 = new LinkedListClass();
            LinkedList <string> ll  = new LinkedList <string>();
            //// creating one file path object
            string text = File.ReadAllText(utility.FileForUnoderedList());

            //// spliting the text in spaces
            string[] word = text.Split(new char[] { ' ' });
            Console.WriteLine("LINKED LIST FILE");
            foreach (string list in word)
            {
                ll1.AddFirst(list);
            }
            ll1.Print();

            foreach (string list in ll)
            {
                Console.WriteLine(list);
            }

            //// check the length of character in text file
            Console.WriteLine("THE LENGTH  CHARATER IN FILE  " + text.Length);
            Console.WriteLine("Enetr the String To the Search in  file");
            string search = Console.ReadLine();

            if (Regex.IsMatch(search.Replace(" ", string.Empty), @"^[a-zA-Z]+$"))
            {
                //// searching the element in present in the file
                if (ll.Contains(search))
                {
                    Console.WriteLine("seaching the word contain in file and remove from file");
                    ll.Remove(search);
                }
                else
                {
                    Console.WriteLine("contain word is not Seaching From File and added in the list");
                    ll.AddLast(search.Replace(" ", string.Empty));
                }
            }
            else
            {
                Console.WriteLine("FILE ONLY CHARATER AND LETTER ACCEPERD");
            }

            foreach (string list in ll)
            {
                Console.WriteLine(list);
            }

            string resultStr = string.Join(" ", ll);

            using (StreamWriter streamWriter = new StreamWriter(utility.ResultForUnderedlist()))
            {
                streamWriter.WriteLine(resultStr + " ");
            }
            Console.ReadLine();
        }
        /// <summary>
        /// Method to execute the prime anagram stack demo.
        /// </summary>
        public void PrimeAnagramStackDemo()
        {
            try
            {
                int[,] primenumbers = new int[10, 50];
                int i = 0, j;
                primenumbers[0, 0] = 0;
                int[,] anagram     = new int[10, 20];

                PrimeAnagram pa = new PrimeAnagram();
                anagram = pa.PrimeAnagramDemo();

                PrimeAnagramClass pac;
                //// Collection Linked list
                LinkedList <PrimeAnagramClass> llpac = new LinkedList <PrimeAnagramClass>();
                //// Custom Linked list
                LinkedListClass llc = new LinkedListClass();
                for (i = 0; i < 10; i++)
                {
                    pac = new PrimeAnagramClass();
                    pac.SetRange(anagram[i, 0]);
                    for (j = 1; anagram[i, j] != 0; j++)
                    {
                        pac.SetAnagrams(anagram[i, j]);
                    }
                    //// collection linked list
                    llpac.AddFirst(pac);
                    //// Custom Linked list
                    llc.AddFirst(pac);
                }
                //// for collection linked list
                for (i = 0; i < 10; i++)
                {
                    Console.WriteLine("In range {0} - {1} ", llpac.First.Value.GetRange().ToString(), llpac.First.Value.GetRange() + 100);
                    int[] ana = llpac.First.Value.GetAnagrams();
                    foreach (int inte in ana)
                    {
                        if (inte != 0)
                        {
                            Console.Write(inte + " ");
                        }
                        else
                        {
                            break;
                        }
                    }

                    llpac.RemoveFirst();
                    Console.WriteLine();
                }

                //// for custom linked list
                Console.WriteLine("****************************For custom linked list**************************************");
                for (i = 0; i < 10; i++)
                {
                    pac = (PrimeAnagramClass)llc.GetFirst().GetData();
                    Console.WriteLine("In range {0} - {1} ", pac.GetRange(), pac.GetRange() + 100);
                    int[] ana = pac.GetAnagrams();
                    foreach (int inte in ana)
                    {
                        if (inte != 0)
                        {
                            Console.Write(inte + " ");
                        }
                        else
                        {
                            break;
                        }
                    }

                    llc.DeleteFirst();
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The process is stopped because " + e);
            }
        }