-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathDeleteaNode.java
More file actions
32 lines (30 loc) · 691 Bytes
/
Copy pathDeleteaNode.java
File metadata and controls
32 lines (30 loc) · 691 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
/*
Insert Node at the end of a linked list
head pointer input could be NULL as well for empty list
Node is defined as
class Node {
int data;
Node next;
}
*/
// This is a "method-only" submission.
// You only need to complete this method.
Node Delete(Node head, int position) {
Node temp = new Node();
Node ptr = new Node();
temp = head;
if(position==0){
ptr.data = head.data;
head = head.next;
ptr = null;
}
else{
for(int i=0;i<position-1;i++){
temp = temp.next;
}
ptr.data = temp.next.data;
temp.next = temp.next.next;
ptr = null;
}
return head;
}