Question #37976

MusicCDSwap(int n1, int n2): This method will swap the node at
position n1 with the node at position n2.

can anyone help me to code out this method for C#? n1 and n2 represents the position of the nodes

Expert's answer

Answer on Question#37976- Programming, C#

1. MusicCDSwap(int n1, int n2): This method will swap the node at position n1 with the node at position n2.

can anyone help me to code out this method for C#? n1 and n2 represents the position of the nodes

Solution.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n1 = 4, n2 = 5;
            Console.WriteLine("N1=" + n1 + " N2=" + n2 + "\n\n");
            MusicCDSwap(ref n1, ref n2);
            Console.WriteLine("N1=" + n1 + " N2=" + n2);
            Console.Read();
        }
        private static void MusicCDSwap(ref int n1, ref int n2)
        {
            int t = n1;
            n1 = n2;
            n2 = t;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS