题目如下
#include<stdio.h> #include<stdlib.h> typedef int ElemType; typedef struct LNode{ ElemType data; struct LNode *next; }LNode,*LinkList; //尾插法 LinkList List_TailInsert(LinkList &L) { ElemType x; L=(LinkList)malloc(sizeof(LNode)); LNode *s,*r=L; printf("请输入单链表各个节点,以9999结束!\n"); scanf("%d",&x); while(x!=9999) { s=(LNode*)malloc(sizeof(LNode)); s->data=x; r->next=s; r=s; scanf("%d",&x); } r->next=NULL; return L; } int Length(LinkList L) { LNode *p=L; int count=0; while(p->next!=NULL) { p=p->next; count++; } return count; } LinkList DisCreat(LinkList &A){ LinkList B=(LinkList)malloc(sizeof(LNode)); B->next=NULL; LNode *p=A->next,*q; LNode *ra=A; while(p!=NULL) { ra->next=p,ra=p; p=p->next; q=p->next; p->next=B->next; B->next=p; p=q; } ra->next=NULL; return B; } int main(){ LinkList L; LinkList R,S; R=List_TailInsert(L); S=DisCreat(R); LNode *p=S; while(p->next!=NULL){ p=p->next; printf("->%d",p->data); } }