链表逆置合集
链表逆置 #include<bits/stdc++.h> using namespace std; struct LNode { int data; LNode *next; }; void creathead(LNode *&L,int a[],int n)///尾插法 { LNode *r,*s; L=(LNode*)malloc(sizeof(LNode)); L->next=NULL; r=L; for(int i=0; i<n; i++) { s=(LNode*)malloc(sizeof(LNode)); s->data=a[i]; r->next=s; r=r->next; } r->next=NULL; } void reverse(LNode *&L) { LNode *p,*q; p=L->next; L->next=NULL; while(p!=NULL) { q=p; p=p->next; q->next=L->next; L->next=q; } } int main() { LNode *L,*B; int n,c[10000]; scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d",&c[i]); creathead(L,c,n); reverse(L); while(L->next!=NULL) {