Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/shuffle #135 #142

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tw.waterballsa.gaas.citadels.spring.util;

import java.util.Arrays;
import java.util.Random;

public class shuffle {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要可以支援不同類型的洗牌

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class 叫 CitadelsUtils 好了

static void shuffle(int array[], int a) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通常都是寫 int[] array,但這邊用 List 好了, 然後 a 是什麼XD 命名要注意

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈 我的意思是放 List XDD,可以支援不同類型

Random rd = new Random();

for (int i = a - 1; i > 0; i--) {
int j = rd.nextInt(i+1);

int temp = array[i];
array[i] = array[j];
array[j] = temp;
}

System.out.println(Arrays.toString(array));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這個也可以拿掉

}

public static void main(String[] args) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

測試完 這些可以拿掉

int[] ar = {1,2,3,4,5};

int b = ar.length;
shuffle(ar, b);
}
}