链表的逆序 顺序建立
# 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,*head,*tail; head=(LINK *)malloc(sizeof(LINK)); head->next=NULL; tail=head; scanf("%d",&n); for(i=0;i<n;i++) { p=(LINK *)malloc(sizeof(LINK)); scanf("%d",&p->data); p->next=head->next; head->next=p; //tail->next=p; //tail=p; } p=head->next; for(i=0;i<n;i++) { if(i)printf(" "); printf("%d",p->data); p=p->next; } printf("\n"); return 0; }
                    
                
                
            
        
浙公网安备 33010602011771号