コード例 #1
0
        static void Main(string[] args)
        {
            LinkedList list = new LinkedList();
            Console.WriteLine("Append a single student");
            Student ibr = new Student(123, "Ibrahim", "Chen");
            list.Append(ibr);
            list.Display();
            Console.WriteLine();
            Console.WriteLine("Append a second student");
            Student chris = new Student(55, "Costic", "Sekmen");
            list.Append(chris);
            list.Display();
            Console.WriteLine("Remove a single student");
            Node removed = list.Remove();
            Console.WriteLine("removed Node is TNumber = {0}, Name = {1}, Advisor = {2}", removed.data.TNumber, removed.data.Name, removed.data.Advisor);
            list.Display();
            Console.WriteLine("Remove a single student");
            Node removed2 = list.Remove();
            Console.WriteLine("removed Node is TNumber = {0}, Name = {1}, Advisor = {2}", removed2.data.TNumber, removed2.data.Name, removed2.data.Advisor);
            list.Display();
            Console.WriteLine("Appending 3 students");
            Student ryan = new Student(202, "Ryan", "Hayes");
            list.Append(ibr);
            list.Append(chris);
            list.Append(ryan);
            list.Display();

            Console.WriteLine("Searching for TNumber = 100");
            Node found = list.Search(100);
            if (found != null)
                Console.WriteLine("Found and Name {0}", found.data.Name);
            else
                Console.WriteLine("Not Found");
            Console.WriteLine("");
            Console.WriteLine("Searching for TNumber = 202");
            Node found2 = list.Search(202);
            if (found2 != null)
                Console.WriteLine("Found and Name {0}", found2.data.Name);
            else
                Console.WriteLine("Not Found");
            Console.WriteLine("");
            Console.WriteLine("Inserting Edmund after TNumber 202");
            Student edmund = new Student(34, "Edmund", "Erdemir");
            list.Insert(edmund, 202);
            Console.WriteLine();
            list.Display();
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            LinkedList <int> linkedList = new LinkedList <int>();

            for (int i = 0; i < 7; i++)
            {
                linkedList.Insert(i);
            }
            Console.WriteLine($"Removing first item : {linkedList.RemoveFirst()}");
            Console.WriteLine($"Removing last item : {linkedList.RemoveLast()}");
            Console.WriteLine($"Removing item {linkedList.Remove(3)}");
            Console.WriteLine($"Removing item {linkedList.Remove(1)}");
            Console.WriteLine($"Removing item {linkedList.Remove(5)}");
            Console.WriteLine($"Removing item {linkedList.Remove(2)}");
            Console.WriteLine($"Removing item {linkedList.Remove(4)}");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            LinkedList linkedList = new LinkedList();

            linkedList.AddFirst("first node");
            linkedList.AddLast("last node");
            linkedList.Print();
            object popped = linkedList.Pop();

            Console.WriteLine("Pop: " + popped);
            linkedList.Print();
            linkedList.AddLast("second node");
            linkedList.AddLast("third node");
            linkedList.Print();
            int index = linkedList.Search("second node");

            Console.WriteLine("second node is stored at index: " + index);
            linkedList.Insert("before second node", index);
            linkedList.Print();
            Console.ReadLine();
        }