Mógłby mi ktoś powiedzieć gdzie mam błąd bo nie widze. Mam odwrócic kolejność elementów listy
#include <stdio.h>
#include <stdlib.h>
struct list
{
int value;
struct list* next;
};
void init (struct list *h)
{
h->next = 0;
}
void add_after (struct list *l, int value)
{
struct list * x = (struct list *) malloc (sizeof (struct list));
x->value = value;
x->next = l->next;
l->next = x;
}
void print (struct list *h)
{
while ( (h = h->next) )
printf ("%d ", h->value);
printf ("\n");
}
void OdwracanieListy(struct list *l)
{ struct list * nowyl = NULL;
struct list *x;
while(l != NULL)
{ x = l->next;
l->next = nowyl;
nowyl = l;
l = x;
}
l = nowyl;
}
int main(int argc, char *argv[])
{
struct list l;
init (&l);
struct list* cur = &l;
int i;
for (i=1; i<=10; i++)
{
add_after (cur, i);
cur = cur->next;
}
print (&l);
OdwracanieListy(&l);
print(&l);
system("PAUSE");
return 0;
}