链表逆置
# include <stdio.h> # include <malloc.h> # include <string.h> typedef struct node { struct node *next; int data; }LINK; int main() { int i,j,n,leag=0; LINK *p,*q,*head; head=(LINK *)malloc(sizeof(LINK)); head->next=NULL; do { p=(LINK *)malloc(sizeof(LINK)); scanf("%d",&p->data); p->next=head->next; head->next=p; }while(p->data != -1); p=head->next; while(p) { if(leag) printf(" "); if(p->data != -1) { printf("%d",p->data);leag++; } p=p->next; } printf("\n"); return 0; }
浙公网安备 33010602011771号