Hi,

I have this merge sort function in x10:

public def mergeSort(tmp:GrowableRail[Pair[String, Int]],
                        low: Int, high: Int)
   {
      val lo:Int = low;
      val hi:Int = high;

      val N:Int = hi - lo; //elements to sort

      if(N <= 1)
      {
         return 0;
      }

      val mid:Int = lo + (N/2);  //middle index

      //recursively sort left and right halves
      mergeSort(tmp, lo, mid);
      mergeSort(tmp, mid, hi);

      var aux: GrowableRail[Pair[String, Int]] = new
GrowableRail[Pair[String,Int]](N)

      var i:Int = lo;
      var j:Int = mid;

      //merge 2 sorted subarrays
      for(var k:Int = 0; k < N; k++)
      {
         if(i == mid)
         {
            aux.set(tmp(j++), k);
         }
         else if(j == hi)
         {
            aux.set(tmp(i++), k);
         }
         else if(tmp(j).first < tmp(i).first)
         {
            aux.set(tmp(j++), k);
         }
         else
         {
            aux.set(tmp(i++), k);
         }
      }

      //copy back into original array
      for(var k:Int = 0; k < N; k++)
      {
         tmp.set(aux.apply(k), (lo+k));
      }
  }

I have an almost exact copy of it in Java. The Java version works fine so I
thought I could just rewrite it in x10, but it doesn't seem to be working at
all. Is there something about recursion in x10 that is different than Java?

Thanks,

Han Dong
h...@umbc.edu
University of Maryland '10
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to