forked from Paraoia/java-2017f-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5,739 changed files
with
466,070 additions
and
5,187 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.*; | ||
|
||
import java.lang.reflect.Array; | ||
import java.math.*; | ||
import java.util.Arrays; | ||
import java.util.*; | ||
|
||
import java.text.*; | ||
public class SortArray | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
int []arr={ 2,3,1,5,8,6,7,4}; | ||
for (int x = 0; x < arr.length - 1; x++) { | ||
for (int y = x + 1; y < arr.length; y++) { | ||
if (arr[x] > arr[y]) { | ||
int temp = arr[x]; | ||
arr[x] = arr[y]; | ||
arr[y] = temp; | ||
} | ||
} | ||
} | ||
for(int i = 0; i < arr.length ; i++) { | ||
System.out.print(arr[i]); | ||
System.out.print(" "); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package myJavahomework; | ||
enum Color{ | ||
红,橙,黄,绿,蓝,靛,紫; | ||
} | ||
enum NO{ | ||
老大,老二,老三,老四,老五,老六,老七 | ||
} | ||
|
||
public class Huluwa { | ||
private String color; | ||
private String no; | ||
Huluwa(int i){ | ||
color = Color.values()[i].toString(); | ||
no = NO.values()[i].toString(); | ||
} | ||
public int get_no() { | ||
return NO.valueOf(no).ordinal(); | ||
} | ||
public int get_color() { | ||
return Color.valueOf(color).ordinal(); | ||
} | ||
public void print_no() { | ||
System.out.print(no+" "); | ||
} | ||
public void print_color() { | ||
System.out.print(color+" "); | ||
} | ||
public void hop(int i,int j) { | ||
print_no(); | ||
System.out.println(":" + i +"->" + j); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package myJavahomework; | ||
import java.util.Random; | ||
class seat{ | ||
Huluwa hulu; | ||
int position; | ||
seat(Huluwa i,int j){ | ||
hulu = i; | ||
position = j; | ||
} | ||
void exchange(seat i,seat j) { | ||
i.hulu.hop(i.position, j.position); | ||
Huluwa temp = i.hulu; | ||
i.hulu = j.hulu; | ||
j.hulu = temp; | ||
} | ||
} | ||
public class Queue { | ||
private Huluwa[] was; | ||
private seat[] seats; | ||
Queue(){ | ||
was = new Huluwa[7]; | ||
seats = new seat[7]; | ||
for(int i = 0;i < 7;i++) { | ||
was[i] = new Huluwa(i); | ||
seats[i] = new seat(was[i],i); | ||
} | ||
} | ||
void random() { | ||
Random rand = new Random(); | ||
for(int i = 0;i < 7;i++) { | ||
int j = rand.nextInt(7); | ||
Huluwa temp = seats[i].hulu; | ||
seats[i].hulu = seats[j].hulu; | ||
seats[j].hulu = temp; | ||
} | ||
} | ||
void buffer_sort() { | ||
for(int i = 0;i < 6;i++) { | ||
int max = i; | ||
for(int j = i + 1;j < 7;j++) { | ||
if(seats[j].hulu.get_no() < seats[max].hulu.get_no()) | ||
max = j; | ||
} | ||
seats[i].exchange(seats[i], seats[max]); | ||
} | ||
} | ||
void binaryInsertSort() { | ||
for(int i = 1;i < seats.length;i++) { | ||
Huluwa temp = seats[i].hulu; | ||
int low = 0; | ||
int high = i- 1; | ||
while(low <= high) { | ||
int mid = (low+high)/2; | ||
if(seats[mid].hulu.get_color() < temp.get_color()) | ||
{ | ||
low = mid + 1; | ||
} | ||
else | ||
high = mid - 1; | ||
} | ||
for(int j = i - 1;j >= low;j--) | ||
seats[j].exchange(seats[j], seats[j+1]); | ||
seats[low].hulu = temp; | ||
} | ||
} | ||
|
||
void print_no() { | ||
for(int i = 0;i < 7;i++) { | ||
seats[i].hulu.print_no(); | ||
} | ||
System.out.println(); | ||
} | ||
void print_color() { | ||
for(int i = 0;i < 7;i++) { | ||
seats[i].hulu.print_color(); | ||
} | ||
System.out.println(); | ||
} | ||
public static void main(String[]args) { | ||
Queue myqueue = new Queue(); | ||
myqueue.random(); | ||
System.out.println("排序前:"); | ||
myqueue.print_color(); | ||
myqueue.print_no(); | ||
myqueue.binaryInsertSort(); | ||
System.out.println("排序后:"); | ||
myqueue.print_color(); | ||
myqueue.print_no(); | ||
myqueue.random(); | ||
System.out.println("排序前:"); | ||
myqueue.buffer_sort(); | ||
System.out.println("排序后:"); | ||
myqueue.print_color(); | ||
myqueue.print_no(); | ||
} | ||
} |
Oops, something went wrong.