二路归并

#include <iostream>
#include <vector>
using namespace std;

int main()
{

//把两个数组归并排序。看来编程时应尽量避免用大写字母。
int l[5] = {1,3,5,7,8};
int r[5] = {2,4,6,11,12};
int i=0,j=0,k=0;
vector <int> t;

while (i<5 && j<5){
if (l[i] < r[j])
t.push_back(l[i++]);
else
t.push_back(r[j++]);
}

if (i<5)
while (i<5)
t.push_back(l[i++]);
else
while (j<5)
t.push_back(r[j++]);

for (k=0;k<t.size();k++)
cout << t[k] << endl;

}

  

原文地址:https://www.cnblogs.com/baili/p/4844762.html