有序序列合并
#include<stdio.h> int main() { int arr1[] = { 1,3,5,7,9,11}; int arr2[] = { 2,4,6,8,10 }; int n = sizeof(arr1) / sizeof(arr1[0]); int m = sizeof(arr2) / sizeof(arr2[0]); int i = 0; int j = 0; while (i < n && j < m) { if (arr1[i] > arr2[j]) { printf("%d ", arr2[j]); j++; } else { printf("%d ", arr1[i]); i++; } } //当j<m不满足时 if (i < n) { for (; i < n; i++) { //打印数组arr1剩余的元素 printf("%d ", arr1[i]); } } //当i<n不满足时 else { for (; j < m; j++) { //打印数组arr2剩余的元素 printf("%d ", arr2[j]); } } return 0; }