小编Pho*_*nix的帖子

链表反递

我在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 algorithm recursion reverse linked-list

16
推荐指数
3
解决办法
2万
查看次数

在C中编写String.trim()

可能的重复:
在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)

这段代码看起来干净吗?

c trim

7
推荐指数
1
解决办法
1万
查看次数

为什么渔民是最有用的改组算法?

你会说现代版本的fisher yates是最无偏见的改组算法吗?您如何解释数组中的每个元素都有1/n的概率在其原始位置?

algorithm shuffle

4
推荐指数
2
解决办法
4350
查看次数

你如何用Java编写解构函数?

我遇到了这个问题并且正在寻找一些想法?

java

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

algorithm ×2

c ×2

java ×1

linked-list ×1

recursion ×1

reverse ×1

shuffle ×1

trim ×1