代码编写如下,采用了模拟的方法
package Demo1;
import java.util.*;
class Node
{
int val;
int rank;
public Node(int rank,int val)
{
this.rank=rank;
this.val=val;
}
}
public class Pukepai {
public static void main(String[] args) {
ArrayDeque<Node> queue=new ArrayDeque<Node>();
List<Node> res=new ArrayList<Node>();
for(int i=13;i>=1;i--)
{
queue.offer(new Node(i,-1));
}
int count=1;
while(!queue.isEmpty())
{
Node tem=queue.pollLast();
queue.offerFirst(tem);
Node curr=queue.pollLast();
curr.val=count;
res.add(curr);
count++;
}
Collections.sort(res,(a,b)->a.rank-b.rank);
for(Node x:res)
{
System.out.println(x.rank+"-"+x.val);
}
}
}
结果: