The Farey sequences of orders 1 to 8 are:
F1 = {0⁄1, 1⁄1}
F2 = {0⁄1, 1⁄2, 1⁄1}
F3 = {0⁄1, 1⁄3, 1⁄2, 2⁄3, 1⁄1}
F4 = {0⁄1, 1⁄4, 1⁄3, 1⁄2, 2⁄3, 3⁄4, 1⁄1}
F5 = {0⁄1, 1⁄5, 1⁄4, 1⁄3, 2⁄5, 1⁄2, 3⁄5, 2⁄3, 3⁄4, 4⁄5, 1⁄1}
F6 = {0⁄1, 1⁄6, 1⁄5, 1⁄4, 1⁄3, 2⁄5, 1⁄2, 3⁄5, 2⁄3, 3⁄4, 4⁄5, 5⁄6, 1⁄1}
F7 = {0⁄1, 1⁄7, 1⁄6, 1⁄5, 1⁄4, 2⁄7, 1⁄3, 2⁄5, 3⁄7, 1⁄2, 4⁄7, 3⁄5, 2⁄3, 5⁄7, 3⁄4, 4⁄5, 5⁄6, 6⁄7, 1⁄1}
F8 = {0⁄1, 1⁄8, 1⁄7, 1⁄6, 1⁄5, 1⁄4, 2⁄7, 1⁄3, 3⁄8, 2⁄5, 3⁄7, 1⁄2, 4⁄7, 3⁄5, 5⁄8, 2⁄3, 5⁄7, 3⁄4, 4⁄5, 5⁄6, 6⁄7, 7⁄8, 1⁄1}
At nth level, a new fractional a+b/c+d is inserted between two adjacent fractions A/C and b/d only when c+d<=n. The following procedure, for a given number of natural numbers n, is continuously extended to create the nth grade of the fractional list.
The data structure used is a linked list node
public class Node {
private int upval;//分子
private int dnval;//分母
private Node next;
public Node(int up, int down) {
upval = up;
dnval = down;
next = null;
}
public Node(int up, int down, Node next) {
upval = up;
dnval = down;
this.next = next;
}
public int getUpval() {
return upval;
}
public void setUpval(int upval) {
this.upval = upval;
}
public int getDnval() {
return dnval;
}
public void setDnval(int dnval) {
this.dnval = dnval;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}