From ecfd7d8e89d292add03c4b67efaa54ea5bc4bf78 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Tue, 14 May 2019 12:35:38 +0900 Subject: [PATCH 01/14] Update BubbleSort.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BubbleSortクラスのsort(int[] ary)メソッドを作成 --- src/jp/co/cis/sort/BubbleSort.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/jp/co/cis/sort/BubbleSort.java b/src/jp/co/cis/sort/BubbleSort.java index 619c4da..0c36102 100644 --- a/src/jp/co/cis/sort/BubbleSort.java +++ b/src/jp/co/cis/sort/BubbleSort.java @@ -12,8 +12,19 @@ public class BubbleSort { * @return */ public int[] sort(int[] ary) { - // TODO バブルソートで並び替える処理を実装してください。 - return ary; + + int aryLength = ary.length; + int changeNum = aryLength - 1; + for(int i=changeNum; i>0; i--){ + for(int j=0; jary[i+1]){ + int temNum = ary[i+1]; + ary[i+1] = ary[i]; + ary[i] = temNum; + } + } + } + return ary; } } From b09b2c7b71ad39b218a34bdd4b900b02ac6b3b6f Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Tue, 14 May 2019 19:23:19 +0900 Subject: [PATCH 02/14] =?UTF-8?q?Fix=20=E3=80=80BubbleSort.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit コードが間違っていたので修正しました。 --- src/jp/co/cis/sort/BubbleSort.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/jp/co/cis/sort/BubbleSort.java b/src/jp/co/cis/sort/BubbleSort.java index 0c36102..e57fd39 100644 --- a/src/jp/co/cis/sort/BubbleSort.java +++ b/src/jp/co/cis/sort/BubbleSort.java @@ -13,14 +13,18 @@ public class BubbleSort { */ public int[] sort(int[] ary) { + /** + * aryLengthで配列の長さを取得 + * changeNumは配列の入れ替えをする回数を表します + */ int aryLength = ary.length; int changeNum = aryLength - 1; for(int i=changeNum; i>0; i--){ for(int j=0; jary[i+1]){ - int temNum = ary[i+1]; - ary[i+1] = ary[i]; - ary[i] = temNum; + if(ary[j]>ary[j+1]){ + int temNum = ary[j+1]; + ary[j+1] = ary[j]; + ary[j] = temNum; } } } From ac19af2577de4a72777b087376631c984c3c07cc Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Fri, 24 May 2019 10:31:00 +0900 Subject: [PATCH 03/14] update SelectionSort.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sortメソッドを実装 --- src/jp/co/cis/sort/BubbleSort.java | 47 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/jp/co/cis/sort/BubbleSort.java b/src/jp/co/cis/sort/BubbleSort.java index e57fd39..c69f478 100644 --- a/src/jp/co/cis/sort/BubbleSort.java +++ b/src/jp/co/cis/sort/BubbleSort.java @@ -1,10 +1,10 @@ package jp.co.cis.sort; /** - * バブルソートで並び替えるクラスです。 + * 選択ソートで配列の値を並び替えるクラスです。 * */ -public class BubbleSort { +public class SelectionSort { /** * 配列の値を小さい順に並び替えた結果を返却します。 @@ -12,23 +12,34 @@ public class BubbleSort { * @return */ public int[] sort(int[] ary) { - - /** - * aryLengthで配列の長さを取得 - * changeNumは配列の入れ替えをする回数を表します - */ - int aryLength = ary.length; - int changeNum = aryLength - 1; - for(int i=changeNum; i>0; i--){ - for(int j=0; jary[j+1]){ - int temNum = ary[j+1]; - ary[j+1] = ary[j]; - ary[j] = temNum; - } + //受け取る配列の長さ + int aryLength = ary.length; + //最大値を探す処理をする回数 + int changeNum = aryLength - 1; + + for (int i = 1; i <= changeNum; i++) { + //左端(最大値を入れる場所)のindex番号 + int tempAryIndex = i - 1; + //最大値があるindex番号を受け取る + int maxAryIndex = i - 1; + //最大値を受け取る + int maxAryNum = ary[i - 1]; + + //最大値をもつindex番号を調べる + for (int j = tempAryIndex; j <= changeNum; j++) { + if (maxAryNum < ary[j]) { + maxAryNum = ary[j]; + maxAryIndex = j; + } + } + + //左端と最大値を持つ配列要素を入れ替える + int tempNum = ary[tempAryIndex]; + ary[tempAryIndex] = ary[maxAryIndex]; + ary[maxAryIndex] = tempNum; } - } - return ary; + + return ary; } } From 071cbb4214b300fb382ec1396efb18c20d5384a8 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Fri, 24 May 2019 10:32:49 +0900 Subject: [PATCH 04/14] Update SelectionSort.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sortメソッドの実装 --- src/jp/co/cis/sort/SelectionSort.java | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/jp/co/cis/sort/SelectionSort.java b/src/jp/co/cis/sort/SelectionSort.java index 1cbcbcb..c69f478 100644 --- a/src/jp/co/cis/sort/SelectionSort.java +++ b/src/jp/co/cis/sort/SelectionSort.java @@ -12,7 +12,33 @@ public class SelectionSort { * @return */ public int[] sort(int[] ary) { - // TODO 選択ソートで並び替える処理を実装してください。 + //受け取る配列の長さ + int aryLength = ary.length; + //最大値を探す処理をする回数 + int changeNum = aryLength - 1; + + for (int i = 1; i <= changeNum; i++) { + //左端(最大値を入れる場所)のindex番号 + int tempAryIndex = i - 1; + //最大値があるindex番号を受け取る + int maxAryIndex = i - 1; + //最大値を受け取る + int maxAryNum = ary[i - 1]; + + //最大値をもつindex番号を調べる + for (int j = tempAryIndex; j <= changeNum; j++) { + if (maxAryNum < ary[j]) { + maxAryNum = ary[j]; + maxAryIndex = j; + } + } + + //左端と最大値を持つ配列要素を入れ替える + int tempNum = ary[tempAryIndex]; + ary[tempAryIndex] = ary[maxAryIndex]; + ary[maxAryIndex] = tempNum; + } + return ary; } From b75c65ae108d76a2e714913e9a0ad9331231c5f5 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Fri, 31 May 2019 09:14:11 +0900 Subject: [PATCH 05/14] Create InsertionSort.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sortメソッドの実装 --- src/jp/co/cis/sort/InsertionSort.java | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/jp/co/cis/sort/InsertionSort.java diff --git a/src/jp/co/cis/sort/InsertionSort.java b/src/jp/co/cis/sort/InsertionSort.java new file mode 100644 index 0000000..6c39429 --- /dev/null +++ b/src/jp/co/cis/sort/InsertionSort.java @@ -0,0 +1,36 @@ +package jp.co.cis.sort; + +/** + * 挿入ソートで配列の値を並び替えるクラスです。 + * + */ +public class InsertionSort { + + /** + * 配列の値を小さい順に並び替えた結果を返却します。 + * @param ary + * @return + */ + public int[] sort(int[] ary) { + + int aryLength = ary.length; + + for (int i = 0; i < aryLength - 1; i++) { + //注目する配列の位置を1から最後尾まで順にずらすループ処理 + for (int j = i + 1; j > 0; j--) { + //左側の配列より値が大きければ入れ替える。小さければ正しい位置なのでループを抜け出す。 + if (ary[j] < ary[j - 1]) { + int tmp = ary[j - 1]; + ary[j - 1] = ary[j]; + ary[j] = tmp; + } else { + break; + } + + } + + } + + return ary; + } +} From ce8a0d8780d956f6506bc99de696475b411bd761 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Tue, 11 Jun 2019 19:01:08 +0900 Subject: [PATCH 06/14] upload jp.co.cis.search folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BinaryTreeクラスを実装 --- src/jp/co/cis/search/BinaryTree.java | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/jp/co/cis/search/BinaryTree.java diff --git a/src/jp/co/cis/search/BinaryTree.java b/src/jp/co/cis/search/BinaryTree.java new file mode 100644 index 0000000..4fc3ca0 --- /dev/null +++ b/src/jp/co/cis/search/BinaryTree.java @@ -0,0 +1,44 @@ +package jp.co.cis.search; + +/** + * 二分木を用いて探索するクラスです + * + */ +public class BinaryTree { + + /** + * 配列aryからsearchの位置を探索します。 + * @param ary + * @param search + * @return + */ + public int search(int[] ary, int search) { + // TODO 二分木で探索する処理を実装してください。 + + int length = ary.length; + + //考える配列の一番小さいindex番号 + int left = 1; + //考える配列の一番大きいindex番号 + int right = length; + + int tmp = right + left; + + //配列の数の中央値の値(tmp/2)が求める値と一致するまでループする + //(tmp/2-1) としているのは配列は0から始まるが、配列の数は1から数えているため + while (ary[tmp / 2 - 1] != search) { + if (ary[tmp / 2 - 1] > search) { + right = tmp / 2; + System.out.println("right" + right); + } else { + left = tmp / 2 + 1; + System.out.println("left" + left); + } + tmp = right + left; + } + + return tmp / 2; + + } + +} From 39d214ff491e0e547c69a61be0243a9c746d21e3 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Tue, 11 Jun 2019 19:05:20 +0900 Subject: [PATCH 07/14] change main.class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main classを変更 --- src/jp/co/cis/Main.java | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/jp/co/cis/Main.java b/src/jp/co/cis/Main.java index 3009320..9b89aa8 100644 --- a/src/jp/co/cis/Main.java +++ b/src/jp/co/cis/Main.java @@ -1,6 +1,7 @@ package jp.co.cis; -import jp.co.cis.sort.SelectionSort; +import jp.co.cis.search.BinaryTree; +import jp.co.cis.sort.InsertionSort; public class Main { @@ -17,17 +18,34 @@ public static void main(String[] args) { System.out.println("before---------"); print(in); + //並び替えが行われる前のin[0] + int search = in[0]; + // バブルソート -// BubbleSort bubbleSort = new BubbleSort(); -// int[] out = bubbleSort.sort(in); - + // BubbleSort bubbleSort = new BubbleSort(); + // int[] out = bubbleSort.sort(in); + // 選択ソート - SelectionSort sort = new SelectionSort(); + // SelectionSort sort = new SelectionSort(); + // int[] out = sort.sort(in); + + // 挿入ソート + InsertionSort sort = new InsertionSort(); int[] out = sort.sort(in); + // ヒープソート + // HeapSort sort = new HeapSort(); + // int[] out = sort.sort(in); + // 変更後表示 - System.out.println("after---------"); + System.out.println("after----------"); print(out); + + BinaryTree tree = new BinaryTree(); + int index = tree.search(out, search); + + System.out.println("探索結果--------"); + System.out.println(search + " は " + index + " 番目"); } /** @@ -37,7 +55,7 @@ public static void main(String[] args) { private static int[] createArray() { int in[] = new int[10]; final int max = in.length; - for(int i = 0; i < max; i++) { + for (int i = 0; i < max; i++) { in[i] = (int) (Math.random() * 100); } @@ -49,7 +67,7 @@ private static int[] createArray() { * @param ary */ private static void print(int[] ary) { - for(int val: ary) { + for (int val : ary) { System.out.print(String.format("%2d", val) + " "); } System.out.println(); From b3629ecdf904168a7058a30e6176de317f56b511 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Mon, 17 Jun 2019 19:00:32 +0900 Subject: [PATCH 08/14] Create Hanoi.java add 2 lines --- src/jp/co/cis/other/Hanoi.java | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/jp/co/cis/other/Hanoi.java diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java new file mode 100644 index 0000000..0bd05c9 --- /dev/null +++ b/src/jp/co/cis/other/Hanoi.java @@ -0,0 +1,42 @@ +package jp.co.cis.other; + +public class Hanoi { + + public static void main(String[] args) { + Hanoi hanoi = new Hanoi(); + hanoi.exec(); + } + + /** + * ハノイの塔の移動させる円盤と塔を出力します + */ + public void exec() { + + move(5, "START", "GOAL", "WORK"); + } + + /** + * 円盤を移動させます + * @param enban 移動させる円盤の枚数 + * @param from 移動元の棒 + * @param to 移動先の棒 + * @param work 作業用の棒 + */ + private void move(int enban, String from, String to, String work) { + + if (enban > 0) { + // 一番下でないなら続ける + + // (1)一番下以外を作業用の棒に移動させる + move(enban - 1, from, work, to); + + // (2)一番下をGOALに移動させる + System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); + + // (3)(1)で移動させた円盤を棒を入れ替えて移動させる + move(enban - 1, work, to, from); + + } + + } +} From fbbc90d2df0383c35e67858852828c7eb5b7fd80 Mon Sep 17 00:00:00 2001 From: =AotoTakeyame Date: Thu, 20 Jun 2019 14:40:33 +0900 Subject: [PATCH 09/14] first --- src/jp/co/cis/hoge.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/jp/co/cis/hoge.txt diff --git a/src/jp/co/cis/hoge.txt b/src/jp/co/cis/hoge.txt new file mode 100644 index 0000000..c2684e0 --- /dev/null +++ b/src/jp/co/cis/hoge.txt @@ -0,0 +1 @@ +hoge \ No newline at end of file From 8bfd613321886d4c3a906ecef33b491f7dbdf8ee Mon Sep 17 00:00:00 2001 From: =AotoTakeyame Date: Thu, 20 Jun 2019 14:42:34 +0900 Subject: [PATCH 10/14] delete --- src/jp/co/cis/Main.java | 76 --------------------------- src/jp/co/cis/hoge.txt | 1 - src/jp/co/cis/other/Hanoi.java | 42 --------------- src/jp/co/cis/search/BinaryTree.java | 44 ---------------- src/jp/co/cis/sort/BubbleSort.java | 45 ---------------- src/jp/co/cis/sort/InsertionSort.java | 36 ------------- src/jp/co/cis/sort/SelectionSort.java | 45 ---------------- 7 files changed, 289 deletions(-) delete mode 100644 src/jp/co/cis/Main.java delete mode 100644 src/jp/co/cis/hoge.txt delete mode 100644 src/jp/co/cis/other/Hanoi.java delete mode 100644 src/jp/co/cis/search/BinaryTree.java delete mode 100644 src/jp/co/cis/sort/BubbleSort.java delete mode 100644 src/jp/co/cis/sort/InsertionSort.java delete mode 100644 src/jp/co/cis/sort/SelectionSort.java diff --git a/src/jp/co/cis/Main.java b/src/jp/co/cis/Main.java deleted file mode 100644 index 9b89aa8..0000000 --- a/src/jp/co/cis/Main.java +++ /dev/null @@ -1,76 +0,0 @@ -package jp.co.cis; - -import jp.co.cis.search.BinaryTree; -import jp.co.cis.sort.InsertionSort; - -public class Main { - - /** - * メインルーチンです。 - * @param args - */ - public static void main(String[] args) { - - // 並び替え対象配列生成 - int in[] = createArray(); - - // 変更前表示 - System.out.println("before---------"); - print(in); - - //並び替えが行われる前のin[0] - int search = in[0]; - - // バブルソート - // BubbleSort bubbleSort = new BubbleSort(); - // int[] out = bubbleSort.sort(in); - - // 選択ソート - // SelectionSort sort = new SelectionSort(); - // int[] out = sort.sort(in); - - // 挿入ソート - InsertionSort sort = new InsertionSort(); - int[] out = sort.sort(in); - - // ヒープソート - // HeapSort sort = new HeapSort(); - // int[] out = sort.sort(in); - - // 変更後表示 - System.out.println("after----------"); - print(out); - - BinaryTree tree = new BinaryTree(); - int index = tree.search(out, search); - - System.out.println("探索結果--------"); - System.out.println(search + " は " + index + " 番目"); - } - - /** - * 0~99の整数配列を生成します。 - * @return - */ - private static int[] createArray() { - int in[] = new int[10]; - final int max = in.length; - for (int i = 0; i < max; i++) { - in[i] = (int) (Math.random() * 100); - } - - return in; - } - - /** - * 配列の値を一行で表示します。 - * @param ary - */ - private static void print(int[] ary) { - for (int val : ary) { - System.out.print(String.format("%2d", val) + " "); - } - System.out.println(); - } - -} diff --git a/src/jp/co/cis/hoge.txt b/src/jp/co/cis/hoge.txt deleted file mode 100644 index c2684e0..0000000 --- a/src/jp/co/cis/hoge.txt +++ /dev/null @@ -1 +0,0 @@ -hoge \ No newline at end of file diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java deleted file mode 100644 index 0bd05c9..0000000 --- a/src/jp/co/cis/other/Hanoi.java +++ /dev/null @@ -1,42 +0,0 @@ -package jp.co.cis.other; - -public class Hanoi { - - public static void main(String[] args) { - Hanoi hanoi = new Hanoi(); - hanoi.exec(); - } - - /** - * ハノイの塔の移動させる円盤と塔を出力します - */ - public void exec() { - - move(5, "START", "GOAL", "WORK"); - } - - /** - * 円盤を移動させます - * @param enban 移動させる円盤の枚数 - * @param from 移動元の棒 - * @param to 移動先の棒 - * @param work 作業用の棒 - */ - private void move(int enban, String from, String to, String work) { - - if (enban > 0) { - // 一番下でないなら続ける - - // (1)一番下以外を作業用の棒に移動させる - move(enban - 1, from, work, to); - - // (2)一番下をGOALに移動させる - System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); - - // (3)(1)で移動させた円盤を棒を入れ替えて移動させる - move(enban - 1, work, to, from); - - } - - } -} diff --git a/src/jp/co/cis/search/BinaryTree.java b/src/jp/co/cis/search/BinaryTree.java deleted file mode 100644 index 4fc3ca0..0000000 --- a/src/jp/co/cis/search/BinaryTree.java +++ /dev/null @@ -1,44 +0,0 @@ -package jp.co.cis.search; - -/** - * 二分木を用いて探索するクラスです - * - */ -public class BinaryTree { - - /** - * 配列aryからsearchの位置を探索します。 - * @param ary - * @param search - * @return - */ - public int search(int[] ary, int search) { - // TODO 二分木で探索する処理を実装してください。 - - int length = ary.length; - - //考える配列の一番小さいindex番号 - int left = 1; - //考える配列の一番大きいindex番号 - int right = length; - - int tmp = right + left; - - //配列の数の中央値の値(tmp/2)が求める値と一致するまでループする - //(tmp/2-1) としているのは配列は0から始まるが、配列の数は1から数えているため - while (ary[tmp / 2 - 1] != search) { - if (ary[tmp / 2 - 1] > search) { - right = tmp / 2; - System.out.println("right" + right); - } else { - left = tmp / 2 + 1; - System.out.println("left" + left); - } - tmp = right + left; - } - - return tmp / 2; - - } - -} diff --git a/src/jp/co/cis/sort/BubbleSort.java b/src/jp/co/cis/sort/BubbleSort.java deleted file mode 100644 index c69f478..0000000 --- a/src/jp/co/cis/sort/BubbleSort.java +++ /dev/null @@ -1,45 +0,0 @@ -package jp.co.cis.sort; - -/** - * 選択ソートで配列の値を並び替えるクラスです。 - * - */ -public class SelectionSort { - - /** - * 配列の値を小さい順に並び替えた結果を返却します。 - * @param ary - * @return - */ - public int[] sort(int[] ary) { - //受け取る配列の長さ - int aryLength = ary.length; - //最大値を探す処理をする回数 - int changeNum = aryLength - 1; - - for (int i = 1; i <= changeNum; i++) { - //左端(最大値を入れる場所)のindex番号 - int tempAryIndex = i - 1; - //最大値があるindex番号を受け取る - int maxAryIndex = i - 1; - //最大値を受け取る - int maxAryNum = ary[i - 1]; - - //最大値をもつindex番号を調べる - for (int j = tempAryIndex; j <= changeNum; j++) { - if (maxAryNum < ary[j]) { - maxAryNum = ary[j]; - maxAryIndex = j; - } - } - - //左端と最大値を持つ配列要素を入れ替える - int tempNum = ary[tempAryIndex]; - ary[tempAryIndex] = ary[maxAryIndex]; - ary[maxAryIndex] = tempNum; - } - - return ary; - } - -} diff --git a/src/jp/co/cis/sort/InsertionSort.java b/src/jp/co/cis/sort/InsertionSort.java deleted file mode 100644 index 6c39429..0000000 --- a/src/jp/co/cis/sort/InsertionSort.java +++ /dev/null @@ -1,36 +0,0 @@ -package jp.co.cis.sort; - -/** - * 挿入ソートで配列の値を並び替えるクラスです。 - * - */ -public class InsertionSort { - - /** - * 配列の値を小さい順に並び替えた結果を返却します。 - * @param ary - * @return - */ - public int[] sort(int[] ary) { - - int aryLength = ary.length; - - for (int i = 0; i < aryLength - 1; i++) { - //注目する配列の位置を1から最後尾まで順にずらすループ処理 - for (int j = i + 1; j > 0; j--) { - //左側の配列より値が大きければ入れ替える。小さければ正しい位置なのでループを抜け出す。 - if (ary[j] < ary[j - 1]) { - int tmp = ary[j - 1]; - ary[j - 1] = ary[j]; - ary[j] = tmp; - } else { - break; - } - - } - - } - - return ary; - } -} diff --git a/src/jp/co/cis/sort/SelectionSort.java b/src/jp/co/cis/sort/SelectionSort.java deleted file mode 100644 index c69f478..0000000 --- a/src/jp/co/cis/sort/SelectionSort.java +++ /dev/null @@ -1,45 +0,0 @@ -package jp.co.cis.sort; - -/** - * 選択ソートで配列の値を並び替えるクラスです。 - * - */ -public class SelectionSort { - - /** - * 配列の値を小さい順に並び替えた結果を返却します。 - * @param ary - * @return - */ - public int[] sort(int[] ary) { - //受け取る配列の長さ - int aryLength = ary.length; - //最大値を探す処理をする回数 - int changeNum = aryLength - 1; - - for (int i = 1; i <= changeNum; i++) { - //左端(最大値を入れる場所)のindex番号 - int tempAryIndex = i - 1; - //最大値があるindex番号を受け取る - int maxAryIndex = i - 1; - //最大値を受け取る - int maxAryNum = ary[i - 1]; - - //最大値をもつindex番号を調べる - for (int j = tempAryIndex; j <= changeNum; j++) { - if (maxAryNum < ary[j]) { - maxAryNum = ary[j]; - maxAryIndex = j; - } - } - - //左端と最大値を持つ配列要素を入れ替える - int tempNum = ary[tempAryIndex]; - ary[tempAryIndex] = ary[maxAryIndex]; - ary[maxAryIndex] = tempNum; - } - - return ary; - } - -} From a7a53bee89eb6fcf7e82cfd8f64cd0484243b8d6 Mon Sep 17 00:00:00 2001 From: =AotoTakeyame Date: Thu, 20 Jun 2019 15:32:13 +0900 Subject: [PATCH 11/14] hoge --- src/jp/co/cis/other/Hanoi.java | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java index 7bff639..c5611df 100644 --- a/src/jp/co/cis/other/Hanoi.java +++ b/src/jp/co/cis/other/Hanoi.java @@ -1,7 +1,7 @@ package jp.co.cis.other; public class Hanoi { - + public static void main(String[] args) { Hanoi hanoi = new Hanoi(); hanoi.exec(); @@ -11,10 +11,10 @@ public static void main(String[] args) { * ハノイの塔の移動させる円盤と塔を出力します */ public void exec() { - + move(5, "START", "GOAL", "WORK"); } - + /** * 円盤を移動させます * @param enban 移動させる円盤の枚数 @@ -23,21 +23,22 @@ public void exec() { * @param work 作業用の棒 */ private void move(int enban, String from, String to, String work) { - + if(enban > 0) { // 一番下でないなら続ける - + // (1)一番下以外を作業用の棒に移動させる - - + move(enban-1 , from , work , end); + // (2)一番下をGOALに移動させる System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); - + // (3)(1)で移動させた円盤を棒を入れ替えて移動させる + move(enban-1 , work , end , from); + + } + + - } - - - } } From f8d523f31d4cbaf26a426a0a2dd9c445592480d0 Mon Sep 17 00:00:00 2001 From: AotoTakeyama <50577559+AotoTakeyama@users.noreply.github.com> Date: Thu, 20 Jun 2019 15:45:52 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=E3=81=BB=E3=81=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hoge --- src/jp/co/cis/other/Hanoi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java index c5611df..b0846d6 100644 --- a/src/jp/co/cis/other/Hanoi.java +++ b/src/jp/co/cis/other/Hanoi.java @@ -28,7 +28,7 @@ private void move(int enban, String from, String to, String work) { // 一番下でないなら続ける // (1)一番下以外を作業用の棒に移動させる - move(enban-1 , from , work , end); + move(enban-1 ,from,work,end); // (2)一番下をGOALに移動させる System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); From b874b8de6601b3c55fb1e3ce89bb6d18f1d34a2b Mon Sep 17 00:00:00 2001 From: =AotoTakeyame Date: Thu, 20 Jun 2019 16:55:03 +0900 Subject: [PATCH 13/14] hano --- src/jp/co/cis/other/Hanoi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java index c5611df..4b2110d 100644 --- a/src/jp/co/cis/other/Hanoi.java +++ b/src/jp/co/cis/other/Hanoi.java @@ -28,13 +28,13 @@ private void move(int enban, String from, String to, String work) { // 一番下でないなら続ける // (1)一番下以外を作業用の棒に移動させる - move(enban-1 , from , work , end); + move(enban-1 , from , work , to); // (2)一番下をGOALに移動させる System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); // (3)(1)で移動させた円盤を棒を入れ替えて移動させる - move(enban-1 , work , end , from); + move(enban-1 , work , to , from); } From 8abe234d07f6964390e8b842336011b640016804 Mon Sep 17 00:00:00 2001 From: =AotoTakeyame Date: Thu, 20 Jun 2019 16:58:41 +0900 Subject: [PATCH 14/14] commit --- src/jp/co/cis/other/Hanoi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jp/co/cis/other/Hanoi.java b/src/jp/co/cis/other/Hanoi.java index 4b2110d..a214db3 100644 --- a/src/jp/co/cis/other/Hanoi.java +++ b/src/jp/co/cis/other/Hanoi.java @@ -28,13 +28,13 @@ private void move(int enban, String from, String to, String work) { // 一番下でないなら続ける // (1)一番下以外を作業用の棒に移動させる - move(enban-1 , from , work , to); + move(enban-1 , from , work , to ); // (2)一番下をGOALに移動させる System.out.println(enban + "番の円盤を" + from + "から" + to + "に移動させる"); // (3)(1)で移動させた円盤を棒を入れ替えて移動させる - move(enban-1 , work , to , from); + move(enban-1 , work , to , from ); }