Skip to content

Commit b95428d

Browse files
committed
Code Edits
1 parent 0c3b403 commit b95428d

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed
Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package linkedlists;
22

3-
import linkedlists.RemoveDuplicates.Node;
4-
53
//Given head pointer of a linked list, sort it in ascending order using insertion sort.
64
public class InsertionSortList{
75

8-
static Node head;
6+
Node head;
97

108
static class Node{
119

@@ -35,27 +33,28 @@ public static void main(String args[]){
3533
list1.head.next.next.next.next = new Node(21);
3634
list1.head.next.next.next.next.next = new Node(14);
3735

38-
printlist(head);
36+
printlist(list1.head);
3937
System.out.println("\n"+"test1");
4038

41-
42-
printlist(insertion_sort(head));
39+
printlist(insertion_sort(list1.head));
4340
}
4441
private static Node insertion_sort(Node head1) {
4542

43+
//InsertionSortList list2 = new InsertionSortList();
4644

4745
Node head2 = new Node(head1.data);
4846
head1 = head1.next;
47+
4948
while(head1 != null){
50-
if(head1.data < head2.data){
49+
if(head1.data <= head2.data){
5150
Node temp = new Node(head2.data);
5251
head2 = new Node(head1.data);
5352
head2.next = temp;
5453
head1 = head1.next;
5554
} else if(head1.data > head2.data){
5655
Node start = head2;
5756
while((head1.data > head2.data)&&(head2.next!=null)){
58-
//System.out.println(head1.data+","+head2.data);
57+
System.out.println(head1.data+","+head2.data);
5958
head2= head2.next;
6059
System.out.println(head1.data+","+head2.data+"inside");
6160
}
@@ -73,38 +72,6 @@ private static Node insertion_sort(Node head1) {
7372

7473
}
7574
}
76-
77-
78-
// //head2.data = 0;
79-
// System.out.println("test2");
80-
// while(head1 != null){
81-
// System.out.println("testx");
82-
// if (head2.next == null){
83-
// System.out.println("test3");
84-
// head2 = new Node(head1.data);
85-
// System.out.println(head1.data);
86-
// head1 = head1.next;
87-
// } else if(head1.data < head2.data){
88-
// System.out.println("test4");
89-
// Node temp = new Node(head2.data);
90-
// head2 = new Node(head1.data);
91-
// head2.next = temp;
92-
// head1 = head1.next;
93-
// } else if(head1.data > head2.data){
94-
// System.out.println("test4");
95-
// Node start = head2;
96-
// while(head1.data>head2.data){
97-
// head2 = head2.next;
98-
// }
99-
// Node temp = new Node(head2.data);
100-
// head2 = new Node(head1.data);
101-
// head2.next = temp;
102-
// head1 = head1.next;
103-
// head2 = start;
104-
// }
105-
// }
106-
10775
return head2;
108-
10976
}
11077
}

src/linkedlists/RemoveDuplicates.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class RemoveDuplicates{
88

9-
static Node head;
9+
Node head;
1010

1111
static class Node{
1212

@@ -35,10 +35,10 @@ public static void main(String args[]){
3535
list1.head.next.next.next.next = new Node(21);
3636
list1.head.next.next.next.next.next = new Node(14);
3737

38-
printList(head);
38+
printList(list1.head);
3939
remove_duplicates(list1);
4040
System.out.println("");
41-
printList(head);
41+
printList(list1.head);
4242

4343
}
4444
private static void remove_duplicates(RemoveDuplicates list1) {

0 commit comments

Comments
 (0)