Slideshow

Sunday 24 February 2013

274. Farley fractions of level one is defined as sequence (0/1, 1/1). This sequence is extended in level two to form a sequence (0/1, ½, 1/1), sequence (0/1, 1/3, ½, 2/3, 1/1) at level three, sequence (0/1, ¼, 1/3, ½, 2/3, ¾, 1/1) at level four, so that AT each level n, a new fraction (a+b) / (c+d) is inserted between two neighbor fractions a/c and b/d only if c+d <= n. Devise a procedure, which for a number n entered by the user creates – by constantly extending it – a linked list of fractions at level n.
ans:
List{int info;
int info;
list*next;};
Farely fractions(n){
listI0,I1,x;
info1(I1)=00;
info2(I1)=1;
next(I1)=I2;
info1(I2)=1;
info(I2)=1;
next(I2)=NULL;
for(i=2;i<=n;i++){
x=head[L];
while(x!=nil&&info1(x)+info1(next)(xL)<=i){
listI;
info(Ij)=info2(xo)+info2(next,x0));
info(Ij)=info1(x)+info1(next);
list insert(L,x);
x=next(x) }}}

No comments:

Post a Comment