Skip to content

Commit 10918cd

Browse files
committed
Day3 and Day4
1 parent 9409710 commit 10918cd

File tree

10 files changed

+124
-0
lines changed

10 files changed

+124
-0
lines changed

bin/Day3/Array12.class

1.52 KB
Binary file not shown.

bin/Day3/compareName.class

760 Bytes
Binary file not shown.

bin/Day3/hello.class

1.05 KB
Binary file not shown.

bin/Day4/BubbleSort.class

1.09 KB
Binary file not shown.

bin/Day4/InsertionSorting.class

401 Bytes
Binary file not shown.

bin/Day4/SelectionSort.class

1.12 KB
Binary file not shown.

src/Day3/Array12.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package Day3;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.Comparator;
6+
7+
class hello implements Comparable<hello> {
8+
private int id;
9+
private String name;
10+
11+
public hello(int id, String name) {
12+
super();
13+
this.id = id;
14+
this.name = name;
15+
}
16+
17+
public int getId() {
18+
return id;
19+
}
20+
21+
public void setId(int id) {
22+
this.id = id;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
@Override
34+
public int compareTo(hello o) {
35+
return id - o.getId();
36+
}
37+
38+
}
39+
40+
class compareName implements Comparator<hello> {
41+
42+
@Override
43+
public int compare(hello h1, hello h2) {
44+
return h1.getName().compareTo(h2.getName());
45+
}
46+
47+
}
48+
49+
public class Array12 {
50+
51+
public static void main(String[] args) {
52+
53+
ArrayList<hello> arr = new ArrayList<hello>();
54+
55+
hello h1 = new hello(1, "Ismail");
56+
hello h2 = new hello(3, "Mohammed");
57+
hello h3 = new hello(2, "Kumar");
58+
59+
arr.add(h1);
60+
arr.add(h2);
61+
arr.add(h3);
62+
63+
// Collections.sort(arr, new compareName());
64+
65+
Collections.sort(arr);
66+
for (hello h : arr) {
67+
System.out.println(h.getId() + " " + h.getName());
68+
}
69+
}
70+
}

src/Day4/BubbleSort.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Day4;
2+
3+
public class BubbleSort {
4+
5+
public static void main(String[] args) {
6+
7+
int[] arr = { 2, 7, 4, 1, 5, 3 };
8+
int i, d, temp;
9+
for (i = 0; i < arr.length - 1; i++) {
10+
for (int j = 0; j < arr.length - i - 1; j++) {
11+
if (arr[j] > arr[j + 1]) {
12+
temp = arr[j + 1];
13+
arr[j + 1] = arr[j];
14+
arr[j] = temp;
15+
}
16+
}
17+
}
18+
19+
for (int k : arr) {
20+
System.out.print(k + " ");
21+
}
22+
}
23+
}

src/Day4/InsertionSorting.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package Day4;
2+
3+
public class InsertionSorting {
4+
5+
public static void main(String[] args) {
6+
7+
}
8+
}

src/Day4/SelectionSort.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Day4;
2+
3+
public class SelectionSort {
4+
5+
public static void main(String[] args) {
6+
7+
int[] arr = { 2, 3, 4, 5, 6, 1, 9, 7 };
8+
int len = arr.length;
9+
for (int i = 0; i < len; i++) {
10+
int iMin = i;
11+
for (int j = i + 1; j < len; j++) {
12+
if (arr[j] < arr[iMin])
13+
iMin = j;
14+
int temp = arr[i];
15+
arr[i] = arr[iMin];
16+
arr[iMin] = temp;
17+
}
18+
}
19+
for (int i : arr) {
20+
System.out.print(i + " ");
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)