public void Delete(int key)
        {
            Node temp = Search(key);
            if (temp == null)
            {
                Console.WriteLine("No such item to delete");
                return;
            }

            if (temp!=start && temp != end)
            {
                temp.prev.next = temp.next;
                temp.next.prev = temp.prev;
            }else if(temp == start && temp == end)
            {
                start = null;
                end = null;
            }else if (temp == start && temp != end)
            {
                start = start.next;
                start.prev = null;
            }else
            {
                temp.prev.next = null;
                end = temp.prev;
            }
            size--;
        }
 public void AppendAtStart(Student s)
 {
     Node temp = new Node(s, null, null);
     if (start == null)
     {
         start = temp;
         end = temp;
     }
     else
     {
         temp.next = start;
         start.prev = temp;
         start = temp;
     }
     size++;
 }
 public void AppendAtEnd(Student s)
 {
     Node temp = new Node(s, null, null);
     if (start == null)
     {
         start = temp;
         end = temp;
     }
     else
     {
         temp.prev = end;
         end.next = temp;
         end = temp;
     }
     size++;
 }
        static void Main(string[] args)
        {
            DoubleLinkedList list = new DoubleLinkedList();
            Node tmpNode = new Node();

            Console.WriteLine("Print empty list");
            list.PrintLinkedList();

            Console.WriteLine("Append a single student at start");
            Student ibr = new Student(123, "Ibrahim", "Chen");
            list.AppendAtStart(ibr);
            list.PrintLinkedList();

            Console.WriteLine("Append a second student at start");
            Student chris = new Student(55, "Costic", "Sekmen");
            list.AppendAtStart(chris);
            list.PrintLinkedList();

            Console.WriteLine("Append a third student at end");
            Student bob = new Student(199, "Smith", "Al Nasr");
            list.AppendAtEnd(bob);
            list.PrintLinkedList();

            Console.WriteLine("Insert a student after TNumber = 55");
            Student Jorge = new Student(201, "Lorenzo", "Rogers");
            list.Insert(Jorge, 55);
            list.PrintLinkedList();

            Student tmpStudent = list.Max();
            Console.WriteLine("Student with Maximum TNumber");
            Console.WriteLine("Tnumber = {0}, Name = {1}, Advisor = {2}\n", tmpStudent.TNumber, tmpStudent.Name, tmpStudent.Advisor);
            tmpStudent = list.Min();
            Console.WriteLine("Student with Minimum TNumber");
            Console.WriteLine("Tnumber = {0}, Name = {1}, Advisor = {2}\n", tmpStudent.TNumber, tmpStudent.Name, tmpStudent.Advisor);

            Console.WriteLine("Delete student with TNumber = 55\n");
            list.Delete(55);
            list.PrintLinkedList();

            Console.WriteLine("Remove student at end of list");
            tmpNode = list.RemoveFromEnd();
            Console.WriteLine("Removed Student is Tnumber = {0}, Name = {1}, Advisor = {2}", tmpNode.data.TNumber, tmpNode.data.Name, tmpNode.data.Advisor);
            Console.WriteLine("");
            list.PrintLinkedList();

            Console.WriteLine("Remove student at start of list");
            tmpNode = list.RemoveFromStart();
            Console.WriteLine("Removed Student is Tnumber = {0}, Name = {1}, Advisor = {2}", tmpNode.data.TNumber, tmpNode.data.Name, tmpNode.data.Advisor);
            Console.WriteLine("");
            list.PrintLinkedList();

            tmpStudent = list.Max();
            Console.WriteLine("Student with Maximum TNumber");
            Console.WriteLine("Tnumber = {0}, Name = {1}, Advisor = {2}\n", tmpStudent.TNumber, tmpStudent.Name, tmpStudent.Advisor);
            tmpStudent = list.Min();
            Console.WriteLine("Student with Minimum TNumber");
            Console.WriteLine("Tnumber = {0}, Name = {1}, Advisor = {2}\n", tmpStudent.TNumber, tmpStudent.Name, tmpStudent.Advisor);

            Console.WriteLine("Remove student at start of list");
            tmpNode = list.RemoveFromStart();
            Console.WriteLine("Removed Student is Tnumber = {0}, Name = {1}, Advisor = {2}", tmpNode.data.TNumber, tmpNode.data.Name, tmpNode.data.Advisor);
            Console.WriteLine("");
            list.PrintLinkedList();

            Console.WriteLine("Remove student at start of list with empty list");
            tmpNode = list.RemoveFromStart();
            if (tmpNode != null)
            {
                Console.WriteLine("Removed Student is Tnumber = {0}, Name = {1}, Advisor = {2}", tmpNode.data.TNumber, tmpNode.data.Name, tmpNode.data.Advisor);
                Console.WriteLine("");
            }

            Console.WriteLine("Remove student at end of list with empty list");
            tmpNode = list.RemoveFromEnd();
            if (tmpNode != null)
            {
                Console.WriteLine("Removed Student is Tnumber = {0}, Name = {1}, Advisor = {2}", tmpNode.data.TNumber, tmpNode.data.Name, tmpNode.data.Advisor);
                Console.WriteLine("");
            }
            Console.ReadLine();
        }
 public Node(Student s, Node forward, Node backward)
 {
     data = s;
     prev = backward;
     next = forward;
 }
 public Node()
 {
     data = null;
     prev = null;
     next = null;
 }
 public void Insert(Student s, int previousKey)
 {
     Node current = Search(previousKey);
     if (current != null)
     {
         Node temp = new Node(s, null, null);
         if (current == end)
         {
             temp.prev = current;
             current.next = temp;
             end = temp;
         }
         else
         {
             temp.next = current.next;
             temp.prev = current;
             current.next.prev = temp;
             current.next = temp;
             if (temp.next == null)
             {
                 end = temp;
             }
         }
         size++;
     }
     else
     {
         Console.WriteLine("Insert was not successful");
     }
 }
 public Node RemoveFromStart()
 {
     Node removed = start;
     if (start != null)
     {
         if (start == end)
         {
             start = null;
             end = null;
         }
         else
         {
             start = start.next;
             start.prev = null;
         }
     }
     else
     {
         Console.WriteLine("Empty List");
     }
     size--;
     return removed;
 }
 public DoubleLinkedList()
 {
     start = null;
     end = null;
     size = 0;
 }
 public Node RemoveFromEnd()
 {
     Node removed = end;
     if (end != null)
     {
         if (start == end)
         {
             start = null;
             end = null;
         }
         else
         {
             end.prev.next = null;
             end = end.prev;
         }
     }
     else
     {
         Console.WriteLine("Empty List");
     }
     size--;
     return removed;
 }