-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday27.java
More file actions
54 lines (41 loc) · 1.01 KB
/
day27.java
File metadata and controls
54 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//ques1:Reverse a Doubly Linked List
//link:https://bit.ly/3w6hUaa
class Solution {
public DLLNode reverseDLL(DLLNode head) {
if (head == null || head.next == null){
return head;
}
DLLNode prev = null;
DLLNode cur = head;
while (cur != null) {
prev = cur.prev;
cur.prev = cur.next;
cur.next = prev;
cur = cur.prev;
}
return prev.prev;
}
}
//ques2:
//link:https://bit.ly/3QlEoMx
class Solution {
public Node deleteNode(Node head, int x) {
// code here
Node temp=head;
int i=1;
while(i<x){
temp=temp.next;
i++;
}
if(temp.prev==null){
head=head.next;
head.prev=null;
return head;
}
if(temp.prev!=null)
temp.prev.next=temp.next;
if(temp.next!=null)
temp.next.prev=temp.prev;
return head;
}
}