Example #1
0
        /// <summary>
        /// Function to delete element from the hash
        /// </summary>
        /// <param name="input">input , to be deleted, as a parameter</param>
        /// <param name="hash">hash as a parameter</param>
        public void DeleteFromFile(int input, hash hash)
        {
            hash.Remove(input);
            string changeFile = File.ReadAllText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\HashNumbers.txt", Encoding.UTF8);

            changeFile = changeFile.Replace(input + string.Empty, "0");
            File.WriteAllText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\HashNumbers.txt", changeFile);
        }
Example #2
0
        public static void HashChain()
        {
            try
            {
                Utility utility = new Utility();

                ////Creates array having 11 slots////
                hash[] hash = new hash[11];
                for (int i = 0; i < 11; i++)
                {
                    hash[i] = new hash(i);
                }

                ////Read the numbers from file and display////
                string path = @"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\HashNumbers.txt";
                utility.DispalyHash(hash, path);

                ////Take user input to search it in hash////
                Console.WriteLine("Enter number to be searched");
                int  searchInput = Convert.ToInt32(Console.ReadLine());
                bool find        = false;
                for (int i = 0; i < hash.Length; i++)
                {
                    if (hash[i].Search(searchInput))
                    {
                        find = true;
                        Console.WriteLine(searchInput + " is present in hash. So it is going to be deleted");
                        utility.DeleteFromFile(searchInput, hash[i]);
                        return;
                    }
                }

                if (!find)
                {
                    Console.WriteLine(searchInput + " is not present. So it is going to be addded");
                    utility.InsertInFile(searchInput, hash, path);
                }

                utility.DispalyHash(hash, path);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }