- 将已按升序排好的字符串A和B,按升序归并到字符串c中
#include<iostream>
using namespace std;
//将已按升序排好的字符串A和B,按升序归并到字符串c中
//数据结构中顺序表的归并
void main() {
char a[100], b[100], c[100];
int i=0, j=0, k=0;
cout << "please input string A and B:" << endl;
cin >> a >> b;
while (a[i] != '\0' && b[j] != '\0') {
if (a[i] < b[j]) {
c[k++] = a[i++];
}
else {
c[k++] = b[j++];
}
}
while (a[i] != '\0') {
c[k++] = a[i++];
}
while (b[j] != '\0') {
c[k++] = b[j++];
}
c[k] = '\0';
cout << c << endl;
}
运行结果