Skip to content

Commit f428fcd

Browse files
author
mayiliang
committed
my java project
0 parents  commit f428fcd

File tree

8 files changed

+219
-0
lines changed

8 files changed

+219
-0
lines changed

.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_131"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>javatest</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

src/sorttest/Main.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package sorttest;
2+
public class Main {
3+
public static <E> void main(String[] args) {
4+
for(int i=0;i<20;i++) {
5+
String value="stu"+(int)(Math.random()*100);
6+
Student s1=new Student();
7+
s1.setId(value);
8+
SortUtils.add(s1);
9+
SortUtils.stusort();
10+
}
11+
for(int i=0;i<20;i++) {
12+
String value="tea"+(int)(Math.random()*100);
13+
Teacher s1=new Teacher();
14+
s1.setId(value);
15+
SortUtils.add(s1);
16+
SortUtils.teasort();
17+
}
18+
System.out.println("student:");
19+
for(int i=0;i<20;i++) {
20+
System.out.print(SortUtils.stu.get(i).getId()+" ");
21+
}
22+
System.out.println();
23+
System.out.println("teacher:");
24+
for(int i=0;i<20;i++) {
25+
System.out.print(SortUtils.tea.get(i).getId()+" ");
26+
}
27+
System.out.println();
28+
29+
30+
31+
32+
}
33+
}

src/sorttest/SortUtils.java

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package sorttest;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class SortUtils {
7+
public static List<Student> stu=new ArrayList<Student>();
8+
public static List<Teacher> tea=new ArrayList<Teacher>();
9+
10+
public static <E> void add(E e) {
11+
if(e.getClass()==Student.class) {
12+
Student s1=(Student) e;
13+
14+
stu.add(s1);
15+
16+
}
17+
else if(e.getClass()==Teacher.class) {
18+
Teacher s1=(Teacher) e;
19+
20+
21+
tea.add(s1);
22+
23+
}
24+
25+
}
26+
public static void stusort() {
27+
String value=stu.get(stu.size()-1).getId();
28+
if(stu.size()==1) {
29+
return;
30+
}
31+
if(stu.size()==2) {
32+
if(stu.get(0).getId().compareTo(stu.get(1).getId())<0) {
33+
String xt=stu.get(0).getId();
34+
stu.get(0).setId(stu.get(1).getId());
35+
stu.get(1).setId(xt);
36+
}
37+
return;
38+
}
39+
if(stu.get(0).getId().compareTo(value)<=0) {
40+
for(int j=stu.size()-1;j>=0;j--) {
41+
42+
if(j==0) {
43+
44+
stu.get(j).setId(value);
45+
46+
}
47+
else {
48+
stu.get(j).setId(stu.get(j-1).getId());
49+
}
50+
}
51+
return;
52+
}
53+
for(int i=0;i<stu.size()-2;i++) {
54+
55+
if(stu.get(i).getId().compareTo(value)>0 && stu.get(i+1).getId().compareTo(value)<0 ) {
56+
57+
for(int j=stu.size()-1;j>=i+1;j--) {
58+
59+
if(j==i+1) {
60+
61+
stu.get(j).setId(value);
62+
63+
}
64+
else {
65+
stu.get(j).setId(stu.get(j-1).getId());
66+
}
67+
}
68+
break;
69+
}
70+
71+
}
72+
}
73+
public static void teasort() {
74+
String value=tea.get(tea.size()-1).getId();
75+
if(tea.size()==1) {
76+
return;
77+
}
78+
if(tea.size()==2) {
79+
if(tea.get(0).getId().compareTo(tea.get(1).getId())<0) {
80+
String xt=tea.get(0).getId();
81+
tea.get(0).setId(tea.get(1).getId());
82+
tea.get(1).setId(xt);
83+
}
84+
return;
85+
}
86+
if(tea.get(0).getId().compareTo(value)<=0) {
87+
for(int j=tea.size()-1;j>=0;j--) {
88+
89+
if(j==0) {
90+
91+
tea.get(j).setId(value);
92+
93+
}
94+
else {
95+
tea.get(j).setId(tea.get(j-1).getId());
96+
}
97+
}
98+
return;
99+
}
100+
for(int i=0;i<tea.size()-2;i++) {
101+
102+
if(tea.get(i).getId().compareTo(value)>0 && tea.get(i+1).getId().compareTo(value)<0 ) {
103+
104+
for(int j=tea.size()-1;j>=i+1;j--) {
105+
106+
if(j==i+1) {
107+
108+
tea.get(j).setId(value);
109+
110+
}
111+
else {
112+
tea.get(j).setId(tea.get(j-1).getId());
113+
}
114+
}
115+
break;
116+
}
117+
118+
}
119+
}
120+
121+
}

src/sorttest/Student.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package sorttest;
2+
3+
public class Student {
4+
private String id;
5+
6+
public String getId() {
7+
return id;
8+
}
9+
10+
public void setId(String id) {
11+
this.id = id;
12+
}
13+
14+
15+
}

src/sorttest/Teacher.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package sorttest;
2+
3+
public class Teacher {
4+
private String id;
5+
6+
public String getId() {
7+
return id;
8+
}
9+
10+
public void setId(String id) {
11+
this.id = id;
12+
}
13+
14+
15+
}

0 commit comments

Comments
 (0)