Esempio n. 1
0
        //Delete middle node: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
        static void Main(string[] args)
        {
            LinkListNode head = new LinkListNode(0);
            LinkListNode first = head;
            for(int i = 1; i < 10; i++){
                LinkListNode second = new LinkListNode(i);
                first.setNext(second);
                first = second;
            }

            Console.WriteLine(head.printForward());

            Delete(head.next.next.next.next.next);

            Console.WriteLine(head.printForward());
        }
Esempio n. 2
0
    { //Delete middle node: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
        static void Main(string[] args)
        {
            LinkListNode head  = new LinkListNode(0);
            LinkListNode first = head;

            for (int i = 1; i < 10; i++)
            {
                LinkListNode second = new LinkListNode(i);
                first.setNext(second);
                first = second;
            }

            Console.WriteLine(head.printForward());

            Delete(head.next.next.next.next.next);

            Console.WriteLine(head.printForward());
        }
 public String printForward()
 {
     if (next != null)
     {
         return(data + "->" + next.printForward());
     }
     else
     {
         return(data.ToString());
     }
 }