首页 > 试题广场 >

现有算法如下,说明算法功能,并求给定输入1、2, 3、4、5

[问答题]

现有算法如下,说明算法功能,并求给定输入12, 34567、890时的输出(7)

#include <stdio.h>
#include
<stdlib.h>
typedef 
struct Node {
           int  data;
           struct Node next;
}Node,*list;
void unknown()
 {
Node *p,*H,*q,*r;
int a;
H=NULL;
scanf("%d",&a);
while (a>0)
 {  p=( Node* )malloc(sizeof(Node)
    p-> data=a;
    p-> next=H;
    H=p;
    scanf("%d" ,&a);
}
q=p-> -next;
while (q!=NULL)
 { r=q-> next;
   if(r!=NULL)
      { q-> next =r-> next;
         r-> next q;
        p-> nexter,
        p=q;
        q=p-> >next;}
else
         q=NULL;
}
p=H;
while (p!=NULL)
{  printf("%d    ",p->data);
    p=p-> next;,
}
}



使用前插法创建一个链表,然后逆置
发表于 2018-11-12 12:39:10 回复(0)