Exemple #1
0
        public void Test()
        {
            OrderedLinkedList <int> list = new OrderedLinkedList <int>();

            list.add(10);
            list.add(100);
            list.add(8);
            list.add(25);
            list.add(32);
            list.add(17);
            Console.Write("Before Pop: ");
            list.Print();
            list.pop(3);
            Console.Write("After Pop: ");
            list.Print();
            bool found = list.Search(32);

            if (found)
            {
                Console.WriteLine("32 Found...");
            }
            else
            {
                Console.WriteLine("32 Not Found...");
            }
        }
Exemple #2
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            OrderedLinkedList <int> orderedLinkedList = new OrderedLinkedList <int>();
            StreamReader            streamReader      = new StreamReader(@"C:\Users\Saad Shamim\source\repos\Programming\Data Structure\Numbers.txt");
            string item;

            while ((item = streamReader.ReadLine()) != null)
            {
                orderedLinkedList.add(Convert.ToInt32(item));
            }
            streamReader.Close();
            Console.WriteLine("Items in OrderedLinkedList Linked List are: ");
            orderedLinkedList.Print();
            Console.Write("Enter a Number: ");
            int  number = Convert.ToInt32(Console.ReadLine());
            bool found  = orderedLinkedList.Search(number);

            if (found)
            {
                orderedLinkedList.remove(number);
            }
            else
            {
                orderedLinkedList.add(number);
            }
            Console.WriteLine("Modified Linked List: ");
            orderedLinkedList.Print();
            orderedLinkedList.PrintToFile(false);
        }