求助!逆向单链表,这样做为何实现不了?
//逆向单链表#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node {
intdata;
struct node*next;
} NODE;
NODE *fun(NODE *h)
{
int i;
NODE *p,*q,*r,*head;
head = q = NULL;
p=r=h;
for(i = 0; i < N-1 ; i++)
{
p=r=h;
do
{
q = p;
p = p->next;
if(p->next != NULL) r = q;
}while(p->next != NULL);
q->next = r;
r->next = NULL;
while(head = NULL)
{
head = q;
}
}
return head;
}
NODE *creatlist(inta[])
{NODE*h,*p,*q;
inti;
h=NULL;
for(i=0; i<N; i++)
{q=(NODE *)malloc(sizeof(NODE));
q->data=a;
q->next = NULL;
if (h == NULL)h = p = q;
else {p->next = q;p = q; }
}
returnh;
}
void outlist(NODE*h)
{NODE*p;
p=h;
if (p==NULL)printf("The list is NULL!\n");
else
{printf("\nHead");
do
{printf("->%d", p->data); p=p->next;}
while(p!=NULL);
printf("->End\n");
}
}
void main()
{NODE*head;
head = NULL;
inta={2,4,6,8,10};
head=creatlist(a);
printf("\nThe original list:\n");
outlist(head);
head=fun(head);
printf("\nThe list after inverting :\n");
outlist(head);
}
请问应该怎样做才可以实现逆向单链表
有没有大佬帮我康康啊? qwer_1234 发表于 2020-4-13 20:07
有没有大佬帮我康康啊?
你都不愿意看自己写的代码吗?
写代码的时候还很不认真?
你能告诉我第 31 行是在做什么吗?
while(head = NULL) 我换成IF也不行
页:
[1]