Exemple #1
0
        public void Add(Node1 start1, Node2 start2)
        {
            Node1 p     = start1;
            Node2 q     = start2;
            Node2 dummy = new Node2(0);
            Node2
            int carry = 0;

            while (p != null || q != null)
            {
                int x   = (p != null) ? p.data : 0;
                int y   = (q != null) ? q.data : 0;
                int sum = carry + x + y;
                carry        = sum / 10;
                current.next = new Node2(sum % 10);
                current      = current.next;
                if (p != null)
                {
                    p = p.next;
                }
                if (q != null)
                {
                    q = q.next;
                }
            }
            if (carry > 0)
            {
                current.next = new Node1(carry);
            }
            return
        }
Exemple #2
0
 public void Display(Node1 start)
 {
     while (start != null)
     {
         Console.WriteLine(start.data);
         start = start.next;
     }
 }
Exemple #3
0
        static void Main(string[] args)
        {
            Node1 n1 = new Node1(7);

            n1.next      = new Node1(1);
            n1.next.next = new Node1(6);
            AddLinkedList a = new AddLinkedList();

            a.Reverse(n1);
            a.Display(n1);
        }
Exemple #4
0
        public void Reverse(Node1 start1)
        {
            Node1 current = start1;
            Node1 next    = current.next;
            Node1 prev    = current;

            current = next;
            while (current != null)
            {
                next         = current.next;
                current.next = prev;
                prev         = current;
                current      = next;
            }
            start1.next = null;
            start1      = prev;
        }
Exemple #5
0
 public Node1(int data)
 {
     this.data = data;
     this.next = null;
 }