TigerGirl 0 Newbie Poster

Hi. I am trying to write a mergeSort method, but I keep getting the wrong sorted array.

public static void mergeSort(int[] num, int left,  int leftEnd,
		                               int right, int rightEnd) {
	int [] temp = new int[num.length];
	int position = left; 
	int number = (rightEnd + leftEnd) - 1;
     while( (left <= leftEnd) && (right <= rightEnd) ){
         if( a[ left ] <= a[ leftEnd ]){
            temp[ position] = a[left];
            position ++; 
            left ++; 
          }
         else {
            temp[position] = a[right];
            position ++;
            right ++ ; 
         }
     }   
         while (left <= leftEnd)
         {
            temp[position] = a[left];
            left ++;
            position ++;
         
         }
         
         while (right <= rightEnd)
         {
            temp[position] = a[right];
            right ++;
            position ++;
         
         }
                  
           //modified
         for (int i=0; i < number; i++)
         {
            a[rightEnd] = temp[rightEnd];
            rightEnd --;
         }
      
          
     
  }

Can anyone tell me what I am doing wrong? Thanks.