3331数据结构实验之链表八:Farey序列
2016-10-08 22:13
435 查看
数据结构实验之链表八:Farey序列
#include<bits/stdc++.h> using namespace std; struct node { int a,b; node *next; }; void creat(node *head,int n) { node *t,*p,*q; t=head->next; while (t->next!=NULL) { p=t->next; if (t->b+p->b<=n) { q=new node; q->a=p->a+t->a; q->b=p->b+t->b; t->next=q; q->next=p; } t=t->next; } } void show(node *head) { node *t; t=head->next; int k=0; while (t!=NULL) { k++; if (k%10==0) printf("%d/%d\n",t->a,t->b); else printf("%d/%d\t",t->a,t->b); t=t->next; } } int main() { int n; scanf("%d",&n); node *head,*p,*q; head=new node; head->next=NULL; p=new node; q=new node; p->a=0; p->b=1; q->a=1; q->b=1; head->next=p; p->next=q; q->next=NULL; for (int i=2;i<=n;i++) { creat(head,i); } show(head); return 0; }
相关文章推荐
- SDUTACM 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- SDUT OJ 数据结构实验之链表八:Farey序列
- SDUT 1519 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列 C++
- 数据结构实验之链表八:Farey序列
- sdutacm-数据结构实验之链表八:Farey序列
- SDUT OJ 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- <sudt-ACM>数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列
- 数据结构实验之链表八:Farey序列