英文:
What does a[k++] = l[i++] notation mean
问题
public static void merge(int[] a, int[] l, int[] r, int left, int right) {
int i = 0, j = 0, k = 0;
while (i < left && j < right) {
if (l[i] <= r[j]) {
a[k++] = l[i++];
}
else {
a[k++] = r[j++];
}
}
while (i < left) {
a[k++] = l[i++];
}
while (j < right) {
a[k++] = r[j++];
}
}
英文:
I'm trying to figure out this merge function for merge sort, but I don't understand the line a[k++] = l[i++]. Can someone give me the non-reduced version of what that would look like?
public static void merge(int[] a, int[] l, int[] r, int left, int right) {
int i = 0, j = 0, k = 0;
while (i < left && j < right) {
if (l[i] <= r[j]) {
a[k++] = l[i++];
}
else {
a[k++] = r[j++];
}
}
while (i < left) {
a[k++] = l[i++];
}
while (j < right) {
a[k++] = r[j++];
}
}
答案1
得分: 1
a[k++] = l[i++]; 等同于
a[k] = l[i];
k = k + 1;
i = i + 1;
假设 k = 3
且 i = 5
。
a[k++] = l[i++];
print(k);
print(i);
输出结果: 4 6
等同于
a[k] = l[i];
k = k + 1;
i = i + 1;
print(k);
print(i);
输出结果: 4 6
英文:
a[k++] = l[i++];
is the same as
a[k] = l[i];
k = k + 1;
i = i + 1;
Suppose k = 3
and i = 5
.
a[k++] = l[i++];
print(k);
print(i);
>OUTPUT: 4 6
is the same as
a[k] = l[i];
k = k + 1;
i = i + 1;
print(k);
print(i);
>OUTPUT: 4 6
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论