Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
首先,您在计算
k
时遇到问题:i
的增量放入for
标头中。在 if 语句中执行此操作很令人困惑 - 起初我以为您有一个无限循环,因为您没有递增。for
循环。arr[i]
应该是(*arr)[i]
。k = 1
以便计算第一组中的最后一个元素。由于
memcpy()
不允许源和目标重叠,因此您应该加倍分配,而不是仅仅添加足够的k
元素。复制整个数组,然后按重新排列的顺序将各部分复制回开头。First, you have a problem with your calculation of
k
:i
in thefor
header. It's confusing to do it in theif
statement -- at first I thought you had an infinite loop because you weren't incrementing.for
loop when the condition fails.arr[i]
should be(*arr)[i]
.k = 1
so that the last element in the first group is counted.Since
memcpy()
doesn't allow overlapping source and destination, you should double the allocation, rather than just adding enough fork
elements. Duplicate the entire array, then copy the portions in the rearranged order back to the beginning.