Closed artimisgood closed 5 years ago
#include"stdio.h" #include"stdlib.h" #define ln (sizeof(struct Number)) typedef struct Number { int num; struct Number * next, * pre; }Num; int a = 0; Num *create() { Num *p_new1,*head,*p1; p1 = p_new1 = (Num *)malloc(ln); head = NULL; int m; scanf("%d",&m); while(m != 0) { if(a == 0) { head = p_new1; p1 = p_new1; head->pre = NULL; } else { p_new1->pre = p1; p1 -> next = p_new1; p1 = p1 -> next; } a ++; p1->num = m; scanf("%d",&m); p_new1 = (Num *)malloc(ln); } p1 -> next = NULL; return(head); } void print(Num * head) { Num * q; q = head; while(q -> num != 0) { printf("%d ",q -> num); q = q -> next; } } void printresort(Num * head) { Num * q; q = head; while(q->next) { q = q->next; } while(q) { printf("%d ",q->num); q = q->pre; } } int main() { Num *m; m = create(); printresort(m); return 0; }
链表倒序