/*
 * 合并两个有序数组
 * OS: Windows XP
 * Compiler: Visual C++ 2008
 * Programming Language: C
 * Time: 18:25 2009-12-8
 */    
#include <stdio.h>
#include <stdlib.h>
#define DEBUG
#undef DEBUG
#define MAX_SIZE 20
int main(void)
{
      int a[] = {2, 5, 8, 9, 34, 66, 99, 102};
      int b[] = {3, 4, 7, 12, 223};
      static int c[MAX_SIZE];
      int i = 0, j = 0, k = 0;
      while ((i < sizeof(a) / sizeof(int)) && (j < sizeof(b) / sizeof(int)))
      {
            if (a[i] <= b[j])
            {
                  c[k] = a[i];
                  i++;
            }
            else
            {
                  c[k] = b[j];
                  j++;
            }
            k++;
#if defined (DEBUG)
            printf("i == %d, j == %d, k == %d\n", i, j, k);
#endif // defined(DEBUG)
      }
      while (i < sizeof(a) / sizeof(int))
      {
            c[k] = a[i];
            i++;
            k++;
      }
      while (j < sizeof(b) / sizeof(int))
      {
            c[k] = b[j];
            j++;
            k++;
      }
      for (i = 0; i < k; i++)
      {
            printf("%d%s", c[i], i == k - 1 ? "\n" : " ");
      }
      system("pause");
      return 0;
}