逆转线性列表
答案:1 悬赏:30 手机版
解决时间 2021-04-05 14:58
- 提问者网友:火车头
- 2021-04-04 18:15
逆转线性列表
最佳答案
- 五星知识达人网友:一叶十三刺
- 2021-04-04 18:28
#include
#include
typedef struct point{
int data;
struct point *next;
} node;
node *reverse(node *list)
{
node *t1=NULL,*t2;
while (list)
{
t2=t1;
t1=list;
list=list->next ;
t1->next =t2;
}
return t1;
}
node *creatList(void)
{
node *list=NULL;
int i;
scanf("%d",&i);
if (i!=-1) {
list=malloc(sizeof(node));
list->data =i;
list->next =creatList();
}
return list;
}
void printList(node *list)
{
while (list!=NULL)
{
printf("%d\t",list->data );
list=list->next ;
}
}
int main(void)
{
node *list=creatList();
printList(list);
putchar(10);
list=reverse(list);
printList(list);
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯