-
Notifications
You must be signed in to change notification settings - Fork 1
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
Backend/shuffle #135 #142
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class 叫 CitadelsUtils 好了 |
||
static void shuffle(int array[], int a) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 通常都是寫 int[] array,但這邊用 List 好了, 然後 a 是什麼XD 命名要注意 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 這個也可以拿掉 |
||
} | ||
|
||
public static void main(String[] args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要可以支援不同類型的洗牌