It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,
visit the help center。
6年前关闭。
我正在寻找有关改进此算法的建议。这是一种非常简单的算法,可以在数组中插入数字并在插入后对其进行排序。因此,它是一个很好用的函数,因此我需要尽可能快地运行它。
static inline void sort_insert(int *arr,int target,int size)
{
int i, at;
for(i = 0; i < size && arr[i] != 0 && arr[i] < target; i++)
/* do nothing */;
at = i; // insertion point
/* if the number will be inserted into last postion,we don't need loop */
if (at == size) {
arr[at - 1] = target;
return;
}
for(i = size - 1; i > at; i--)
arr[i] = arr[i - 1];
arr[at] = target;
}
注意:
请避免内置函数。稍后将在汇编中重写此算法。