k

k

  • NA
  • 25
  • 0

How can I make swap function in C#

Oct 28 2008 5:56 PM
pleases tell me how to swap numbers in this case. I try to do but the value of A[i] and A[0] cannot swap each other.

namespace HapInCSharp
{
    class heap
    {
        int heap_size_;
        int priority_level_;
        public int []A = new int[50];


       public void Swap(int a, int b)
        {
            int temp = a;
            a = b;
            b = temp;
        }         
        public void HeapSort(int[] A, int n)
        {
            ...
            for (int i = n ; i >= 1; i--)
            {
                  ...
                  Console.WriteLine(" {0} {1} ", A[i], A[0]);
                  Swap(A[i], A[0]);     
                  Console.WriteLine(" {0} {1} ", A[i], A[0]);  
   
                  ...
            }
         }
}


Answers (3)