我在stanford库中查看下面的代码:
void recursiveReverse(struct node** head_ref)
{
struct node* first;
struct node* rest;
/* empty list */
if (*head_ref == NULL)
return;
/* suppose first = {1, 2, 3}, rest = {2, 3} */
first = *head_ref;
rest = first->next;
/* List has only one node */
if (rest == NULL)
return;
/* put the first element on the end of the list */
recursiveReverse(&rest);
first->next->next = first;
/* tricky step -- see the diagram */
first->next = NULL;
/* fix …Run Code Online (Sandbox Code Playgroud) 可能的重复:
在C中修剪前导/尾随空格的无痛方法?
修剪C中的字符串
嗨伙计们,我在c中编写String trim方法,这是我提出的代码.我认为它可以消除前导和尾随空格,但我希望代码可以更清晰.你能建议改进吗?
void trim(char *String)
{
int i=0;j=0;
char c,lastc;
while(String[i])
{
c=String[i];
if(c!=' ')
{
String[j]=c;
j++;
}
else if(lastc!= ' ')
{
String[j]=c;
j++;
}
lastc = c;
i++;
}
Run Code Online (Sandbox Code Playgroud)
这段代码看起来干净吗?
你会说现代版本的fisher yates是最无偏见的改组算法吗?您如何解释数组中的每个元素都有1/n的概率在其原始位置?