Example #1
0
        public static void UnOrderedlist()
        {
            try
            {
                Linkedlist   list = new Linkedlist();
                StreamReader file = new StreamReader(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\File.txt", Encoding.UTF8);
                string       line;
                while ((line = file.ReadLine()) != null)
                {
                    string[] word = line.Split(' ');
                    for (int i = 0; i < word.Length; i++)
                    {
                        list.Append(word[i]);
                    }
                }

                list.Show();
                string end = file.ReadToEnd();
                file.Close();
                Console.WriteLine();
                Console.WriteLine("Enter word to find");
                string find       = Console.ReadLine();
                string changeFile = File.ReadAllText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\File.txt", Encoding.UTF8);
                if (list.Search(find))
                {
                    list.Remove(find);
                    changeFile = changeFile.Replace(find, string.Empty);
                    File.WriteAllText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\File.txt", changeFile);
                }
                else
                {
                    list.Append(find);
                    using (StreamWriter sw = File.AppendText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\File.txt"))
                    {
                        sw.WriteLine(find);
                    }
                }

                list.Show();
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #2
0
        public static void OrderedList()
        {
            try
            {
                Linkedlist list   = new Linkedlist();
                var        file   = File.ReadAllText(@"C:\Users\Admin\Desktop\Git_Leena\Allprogram\Data_Structure\Numbers.txt", Encoding.UTF8);
                string[]   values = file.Split(',');
                for (int i = 0; i < values.Length; i++)
                {
                    list.Append(Convert.ToInt32(values[i]));
                }

                for (int i = 0; i < list.Size(); i++)
                {
                    for (int j = 0; j < list.Size() - 1; j++)
                    {
                        if (Convert.ToInt32(list.Get(j)) > Convert.ToInt32(list.Get(j + 1)))
                        {
                            int temp = Convert.ToInt32(list.Get(j));
                            list.Put(j, list.Get(j + 1));
                            list.Put(j + 1, temp);
                        }
                    }
                }

                list.Show();
                Console.WriteLine("Enter any number");
                int input = Convert.ToInt32(Console.ReadLine());
                if (list.Search(input))
                {
                    list.Remove(input);
                }
                else
                {
                    list.AddOrder(input);
                }

                list.Show();
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #3
0
 /// <summary>
 /// Initialize the new instance of Hash
 /// </summary>
 /// <param name="index">index as a parameter</param>
 public hash(int index)
 {
     this.index      = index;
     this.linkedList = new Linkedlist();
     this.len++;
 }