We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e415c7e commit 8c4aa0cCopy full SHA for 8c4aa0c
LinkedList/InsertInSortedDLL.java
@@ -0,0 +1,30 @@
1
+public class InsertInSortedDLL {
2
+ public static Node sortedInsert(Node head, int x)
3
+ {
4
+ // add your code here
5
+ Node newNode = new Node(x);
6
+ Node currNode = head;
7
+
8
+ if(x<=head.data){
9
+ newNode.next = head;
10
+ head.prev = newNode;
11
+ return newNode;
12
+ }
13
14
+ while(currNode.next != null && currNode.next.data < x){
15
+ currNode = currNode.next;
16
17
18
+ newNode.prev = currNode;
19
+ newNode.next = currNode.next;
20
+ if(currNode.next != null){
21
22
+ currNode.next.prev = newNode;
23
24
+ currNode.next = newNode;
25
26
+ return head;
27
+ public static void main(String[] args) {
28
29
30
+}
0 commit comments