满意答案
贴上去的程序,排列不好,要排列好的加扣Q: 2 7 8 9 8 2 2 8
#include "list"
#include <iostream>
using namespace std;
list<int> A;
list<int> B;
list<int> C;
int main(int argc, char* argv[])
{
int arryA[] = { 1, 2, 3, 4, 5, 6};
int arryB[] = { 2, 4, 6, 8};
int sizeA = sizeof(arryA)/sizeof(int);
int sizeB = sizeof(arryB)/sizeof(int);
int i = 0;
for(i = 0; i < sizeA; i++)
{
A.push_back(arryA[i]);
}
for(i = 0; i < sizeB; i++)
{
B.push_back(arryB[i]);
}
list<int>::iterator pA = A.begin();
list<int>::iterator pB = B.begin();
while(pA != A.end() && pB !=B.end())
{
if(*pA < *pB)
{
C.push_back(*pA);
pA++;
}
else if(*pA > *pB)
{
C.push_back(*pB);
pB++;
}
else
{
C.push_back(*pA);
pA++;
pB++;
}
}
while(pA != A.end())
{
C.push_back(*pA);
pA++;
}
while(pB != B.end())
{
C.push_back(*pB);
pB++;
}
for(list<int>::iterator pC = C.begin(); pC != C.end(); pC++)
{
printf("%d \t", *pC);
}
printf("\n");
return 0;
}