请写出相应的c语言语法代码:实现有两个递增有序的合并,合并后有序表不允许有重复数据
时间: 2024-05-07 18:16:22 浏览: 36
两个有序链表序列的合并_C语言_
5星 · 资源好评率100%
Sure, here's the code in C language:
```
void mergeSortedArrays(int arr1[], int arr2[], int mergedArr[], int n1, int n2) {
int i = 0, j = 0, k = 0;
while (i < n1 && j < n2) {
if (arr1[i] < arr2[j])
mergedArr[k++] = arr1[i++];
else if (arr2[j] < arr1[i])
mergedArr[k++] = arr2[j++];
else {
mergedArr[k++] = arr1[i++];
j++;
}
}
while (i < n1)
mergedArr[k++] = arr1[i++];
while (j < n2)
mergedArr[k++] = arr2[j++];
}
```
This function takes in two sorted arrays `arr1` and `arr2`, and the sizes of the arrays `n1` and `n2` respectively. It then merges the two arrays into `mergedArr`, without any duplicate values. The resulting merged array will also be sorted in ascending order.
阅读全文