码迷,mamicode.com
首页 > 其他好文 > 详细

3331=数据结构实验之链表八:Farey序列

时间:2019-10-08 23:49:16      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:col   std   链表   for   color   lse   turn   else   date   

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 struct node
 4 {
 5     int date1,date2;
 6     struct node*next;
 7 } node;
 8 int main()
 9 {
10     struct node*p,*head,*end,*q;
11     head=(struct node*)malloc(sizeof(struct node));
12     head->next=NULL;
13     end=head;
14     int n,i;
15     scanf("%d",&n);
16     p=(struct node*)malloc(sizeof(struct node));
17     p->next=NULL;
18     q=(struct node*)malloc(sizeof(struct node));
19     q->next=NULL;
20     head->next=p;
21     p->next=q;
22     q->next=NULL;
23     p->date1=0;
24     p->date2=1;
25     q->date1=1;
26     q->date2=1;
27     for(i=1; i<=n; i++)
28     {
29         end=head->next;
30         while(end->next!=NULL)
31         {
32             p=end->next;
33             if((p->date2+end->date2)<=i)
34             {
35                 q=(struct node*)malloc(sizeof(struct node));
36                 q->date1=end->date1+p->date1;
37                 q->date2=end->date2+p->date2;
38                 q->next=NULL;
39                 end->next=q;
40                 q->next=p;
41                 end=end->next->next;
42             }
43             else
44             {
45                 end=end->next;
46             }
47         }
48     }
49 
50     p=head->next;
51     int mark=0;
52     for(; p!=NULL; p=p->next)
53     {
54         if(mark!=0)printf("\t");
55         mark++;
56         printf("%d/%d",p->date1,p->date2);
57         if(mark==10)printf("\n"),mark=0;
58 
59     }
60     return 0;
61 }

 

3331=数据结构实验之链表八:Farey序列

标签:col   std   链表   for   color   lse   turn   else   date   

原文地址:https://www.cnblogs.com/Angfe/p/11638484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!