int main() { int i; Node *p=NULL, *head=NULL; for (i=0; i<N; i++) { p = malloc(sizeof (Node)); p->n = i; if (head==NULL) head = p; else { p->next = head; head = p; } } for (p=head, i=0; p!=NULL; p=p->next, i++) { printf("%d\t", p->n); if (((i+1)%8) == 0) printf("\n"); } printf("\n"); head = reverse_iter(head); for (p=head, i=0; p!=NULL; p=p->next, i++) { printf("%d\t", p->n); if (((i+1)%8) == 0) printf("\n"); } return 0; }
int main(int argc, char **argv) { List *a = create_iter(6); List *b = create_iter(6); List *rev_a = reverse_iter(a); a->n->n = NULL; b->n->n = NULL; rev_a->n->n = NULL; return 1; }
Node * reverse_iter(Node *head) { if (head == NULL) return head; Node *p = head->next; head->next = NULL; if (p != NULL) { Node *q = reverse_iter(p); p->next = head; return q; } else { return head; } }