posts - 241,  comments - 116,  trackbacks - 0
          import java.util.Scanner;

          public class Josephus {
              private static class Node {
                  public int no;// 編號
                  public Node next;// 下一個節(jié)點

                  public Node(int no) {
                      this.no = no;
                  }
              }

              public static void main(String[] args) {
                  Scanner scanner = new Scanner(System.in);
                  System.out.print("請輸入總?cè)藬?shù):");
                  int totalNum = scanner.nextInt();
                  System.out.print("請輸入報數(shù)的大小:");
                  int cycleNum = scanner.nextInt();
                  Node header = new Node(1);
                  Node pointer = header;
                  for (int i = 2; i <= totalNum; i++) {Hibernate中的悲觀鎖和樂觀鎖
                      pointer.next = new Node(i);
                      pointer = pointer.next;
                  }
                  pointer.next = header;
                  // 初始化環(huán)形鏈表結(jié)束
                  System.out.println("以下是出列的順序:");
                  while (pointer != pointer.next) {
                      for (int i = 1; i < cycleNum; i++) {
                          pointer = pointer.next;
                      }
                      System.out.println(pointer.next.no);
                      pointer.next = pointer.next.next;
                  }
                  System.out.println(pointer.next.no);
              }
          }
          posted on 2011-08-29 09:37 墻頭草 閱讀(229) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          人人游戲網(wǎng) 軟件開發(fā)網(wǎng) 貨運專家
          主站蜘蛛池模板: 甘泉县| 磐安县| 尉氏县| 横峰县| 新宾| 开原市| 宁都县| 淅川县| 屯昌县| 黎平县| 始兴县| 义马市| 双鸭山市| 汕头市| 桂阳县| 搜索| 贵港市| 凉城县| 小金县| 黄浦区| 邓州市| 隆子县| 龙井市| 蒲城县| 景谷| 利津县| 屯昌县| 恭城| 神池县| 神农架林区| 景谷| 林西县| 南陵县| 齐齐哈尔市| 望江县| 泰兴市| 乌兰浩特市| 宁乡县| 齐河县| 抚宁县| 乌兰县|