7. แถวลำดับ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 7-20  เมท็อดผสานข้อมูลในอาเรย์สองแถวให้เป็นหนึ่ง
  public static double[] merge(double[] d1, double[] d2) {
    double[] d3 = new double[d1.length + d2.length];
    int i1 = 0, i2 = 0;
    for (int i3 = 0; i3 < d3.length; i3++) {     
      if (i1 < d1.length && i2 < d2.length) {
        if (d1[i1] < d2[i2]) {
          d3[i3] = d1[i1++];
        } else {
          d3[i3] = d2[i2++];
        }
      } else {
        if (i1 < d1.length) {
          d3[i3] = d1[i1++];
        } else {
          d3[i3] = d2[i2++];
        }
      }
    }
    return d3;
  }
©2009 S.Prasitjutrakul