-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete a node.java
More file actions
41 lines (35 loc) · 837 Bytes
/
Copy pathDelete a node.java
File metadata and controls
41 lines (35 loc) · 837 Bytes
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
const LinkedListNode = class {
constructor(nodeData) {
this.data = nodeData;
this.next = null;
}
};
// Complete the function below
function deleteNode(head, position) {
let temp=head;
let prev = null
if( head===null || head.next===null ){
return null;
}else{
if(position === 0 ){
head=head.next;
return head;
}else if(position == 1){
temp = head.next;
head.next=temp.next;
return head
}else{
for(let i=0;i<position;i++){
prev=temp
temp=temp.next
}
if(temp.next==null){
prev.next=null
return head
}else{
prev.next=temp.next
return head
}
}
}
}