C++数组排序题求解

对两个有序数组进行合并设有如下数组A、B,并假设两个数组的元素都已经有序(从大到小降序排列)。编写程序,合并A、B数组形成一个新的数组C,并使C的元素仍有序(从大到小降序排列)。int A[10]={123,88,86,86,33,15,7,0,-1,-3};int B[10]={86,69,51,50,27,19,15,12,5,2};

  • sharpgun 2012-01-03 09:32
  • 收藏问题 ( 0人收藏 )
  • 举报

你的IE浏览器版本过低,为了提升体验,

建议升级到IE10以上或使用Chrome、搜狗等浏览器!

2个答案
  • E都市网友 2016-12-20 16:55
    #include "stdafx.h" #include using namespace std; int main ( ) { int A[10]={200,129,88,86,33,15,7,0,-1,-3}, B[10]={28,87,51,50,27,19,15,12,5,1}; int i,j,C[20],p; for (i=0;i<=9;i ){ C[i]=A[i]; C[i 10]=B[i];} for (i=0;i<=19;i ){ for (j=i 1;j<=19;j ){ if (C[i]>C[j]){ p=C[i]; C[i]=C[j]; C[j]=p;}} cout<
  • liyuxin1126 2012-01-04 02:19
    #include <iostream.h>void main(){int A[10]={123,88,86,86,33,15,7,0,-1,-3}; int B[10]={86,69,51,50,27,19,15,12,5,2};int* C = new int[20];int* current = A;int* another = B;int* temp;int currentIndex = 0;int anotherIndex = 0;int tempIndex;for(int i = 0; i < 20; i++){if(anotherIndex != 10){if(currentIndex == 10 || current[currentIndex] < another[anotherIndex]){temp = current;current = another;another = temp;tempIndex = currentIndex;currentIndex = anotherIndex;anotherIndex = tempIndex;}}C[i] = current[currentIndex++];}}