1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include<stdio.h> #include<stdlib.h> #define LEN sizeof(struct node) typedef int datatype; typedef struct node { datatype data; struct node *next; }linklist;
linklist *hcirl_creat() {int x; linklist *head,*p,*rear; head=(struct node*)malloc(LEN); head->data=-999; rear=head; printf("\n\t请输入整数以0结尾\n"); scanf("%d",&x); while(x!=0) {p=(struct node*)malloc(LEN); p->data=x; rear->next=p; rear=p; scanf("%d",&x); } rear->next=head; return rear;}
void print_circular( linklist *rb)
{linklist *p,*head; int m=0; head=rb->next; p=head->next; while(p!=head) { printf("%5d",p->data); p=p->next; m++; if((m+1)%10==0) printf("\n"); }printf("\n"); } void main() { linklist *ra,*rb,*rc,*head; ra=hcirl_creat(); rb=hcirl_creat(); head=ra->next; ra->next=rb->next->next; free(rb->next); rb->next=head; rc=rb; print_circular(rb);
}
|