user-0 提问: 链表的逆序问题

回复:
user: user-1
content: #include <stdio.h> #include <malloc.h>  typedef char ElemType; typedef struct Node    {     ElemType data;     struct Node  * next; }Node, *LinkList;  void CreateFromTail(LinkList L) {     Node *r, *s;     char c;     int  flag =1;       /*设置一个标志，初值为1，当输入"$"时，flag为0，建表结束*/ 	r=L; 	while(flag)         /*循环输入表中元素值，将建立新结点s插入表尾*/     {         c=getchar();         if(c!='$')         {             s=(Node*)malloc(sizeof(Node));             s->data=c;             r->next=s;             r=s;         }         else         {             flag=0;             r->next=NULL;   /*将最后一个结点的next链域置为空，表示链表的结束*/         }     } }  void printL(LinkList L) { 	Node *r; 	r=L; 	while(r!=NULL) 	{ 		printf(" %c ",r->data); 		r=r->next; 	} }  LinkList Routine(LinkList head) { 	LinkList pre=NULL,cur=head; 	LinkList next; 	while(cur) 	{ 		next=cur->next; 		cur->next=pre; 		pre=cur; 		cur=next; 	} 	return pre; }  int main() { 	LinkList L; 	Node *s; 	char c; 	c=getchar(); 	s=(Node*)malloc(sizeof(Node));     s->data=c;     L=s; 	CreateFromTail(L); 	printL(L); 	printf(" \n "); 	L=Routine(L); 	printL(L); 	printf(" \n "); 	return 0; }

user: user-2
content: 数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633

user: user-3
content: #include<stdio.h> #include <stdlib.h> #include<malloc.h> //#include <unistd.h>  #define len sizeof(struct Student)  struct Student{     long num;     float score;     struct Student *next; };  int n;  struct Student* creat() {     struct Student *head;     struct Student *p1,*p2;     n=0;     p1=p2=(struct Student *)malloc(len);     scanf("%ld,%f", &p1->num,&p1->score);     head = NULL;     while(p1->num != 0)     {         n=n+1;         if(n==1)         {             head=p1;         }         else         {             p2=p1;             p1=(struct Student *)malloc(len);             if (!p1)                 exit(-1);             p2->next = p1;             scanf("%ld,%f",&p1->num,&p1->score);         }     }     free(p1);    //free last node     p2->next = NULL;      return head; } void print(struct Student *head) {     struct Student *p;      p = head;      if (!p) {         printf("\nEmpty list\n");         return;     }      while(p)     {         printf("%ld %.5f\n",p->num, p->score);         p = p->next;     }      /*        if(head->next!=NULL)        {        p=head;        while(p!=NULL)        {        printf("%ld %.5f\n",p->num,p->score);        p=p->next;        }        }        else        {        printf("\nEmpty list");        }        */ } struct Student  *deundo(struct Student *head)//逆序链表 {     //struct Student *tmp;     //struct Student *p1, *p2;     struct Student *r, *s, *t;      if (!head) {         printf("\nEmpty list\n");         return NULL;     }      r = head;     s = head->next;      head->next = NULL;    /*头结点作为末节点*/     while (s) {         t = s->next;         s->next = r;         r = s;         s = t;     }     head = r;      /*     p2=NULL;     while(head!=NULL)     {         tmp=head->next;         head->next=p2;         p2=head;         head=tmp;     }     head=p2;//     */     return (head); } int main() {     struct Student *head;     //int num,num1;     //float score;     head=creat();     print(head);     head = deundo(head);     printf("\n");     print(head); } 参考一下吧； 逆序后，需要重新返回新的头结点；