テンプレートへの[アルゴリズム]配列

著作権:ソースを明記してくださいhttps://blog.csdn.net/weixin_40937100/article/details/88907714
//用两个数组,两个索引变量

#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std;

template <typename T>
int merge_(T A[], T B[], T C[], int n, int m){
    int i=0, j=0, index=0;
    while(i<n && j<m){
        if(A[i] < B[j]){
            C[index++] = A[i++];
        }
        else{
            C[index++] = B[j++];
        }
    }
    while(i<n) C[index++] = A[i++];
    while(j<m) C[index++] = B[j++];
    return index;
}

int main(){
    int A[] = {1,3,5,7,9};
    int B[] = {2,4,6,8,10};
    int C[12] = {0};
    int res = merge_(A, B, C, 5, 5);
    //cout<<res<<endl;
    for(int i=0;i<10;i++){
        cout<<C[i]<< " ";
    }
    return 0;
}

おすすめ

転載: blog.csdn.net/weixin_40937100/article/details/88907714