You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/thealgorithms/sorts/LinkListSort.java
+50-28Lines changed: 50 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -8,16 +8,18 @@
8
8
9
9
importjava.util.*;
10
10
11
-
publicclassLinkList_Sort {
11
+
publicclassLinkListSort {
12
12
13
13
publicstaticbooleanisSorted(intp[], intoption) {
14
-
try (Scannersc = newScanner(System.in)) {}
14
+
try (Scannersc = newScanner(System.in)) {
15
+
}
15
16
inta[] = p;
16
17
// Array is taken as input from test class
17
18
intb[] = p;
18
19
// array similar to a
19
20
intch = option;
20
-
// Choice is choosed as any number from 1 to 3 (So the linked list will be sorted by Merge sort technique/Insertion sort technique/Heap sort technique)
21
+
// Choice is choosed as any number from 1 to 3 (So the linked list will be
22
+
// sorted by Merge sort technique/Insertion sort technique/Heap sort technique)
21
23
switch (ch) {
22
24
case1:
23
25
Tasknm = newTask();
@@ -26,10 +28,13 @@ public static boolean isSorted(int p[], int option) {
26
28
// New nodes are created and values are added
27
29
fresh = newNode(); // Node class is called
28
30
fresh.val = a[i]; // Node val is stored
29
-
if (start == null) start = fresh; elseprev.next = fresh;
31
+
if (start == null)
32
+
start = fresh;
33
+
else
34
+
prev.next = fresh;
30
35
prev = fresh;
31
36
}
32
-
start = nm.sort_by_mergesort(start);
37
+
start = nm.sortByMergeSort(start);
33
38
// method is being called
34
39
inti = 0;
35
40
for (ptr = start; ptr != null; ptr = ptr.next) {
@@ -38,51 +43,57 @@ public static boolean isSorted(int p[], int option) {
38
43
}
39
44
Arrays.sort(b);
40
45
// array b is sorted and it will return true when checked with sorted list
41
-
LinkList_Sortuu = newLinkList_Sort();
46
+
LinkListSortuu = newLinkListSort();
42
47
if (uu.compare(a, b)) {
43
48
returntrue;
44
49
} else {
45
50
returnfalse;
46
51
}
47
-
// The given array and the expected array is checked if both are same then true is displayed else false is displayed
52
+
// The given array and the expected array is checked if both are same then true
53
+
// is displayed else false is displayed
48
54
case2:
49
55
Nodestart1 = null, prev1 = null, fresh1, ptr1;
50
56
for (inti1 = 0; i1 < a.length; i1++) {
51
57
// New nodes are created and values are added
52
58
fresh1 = newNode(); // New node is created
53
59
fresh1.val = a[i1]; // Value is stored in the value part of the node
54
-
if (start1 == null) start1 = fresh1; elseprev1.next =
0 commit comments