-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm237.java
More file actions
39 lines (37 loc) · 890 Bytes
/
prblm237.java
File metadata and controls
39 lines (37 loc) · 890 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
class node {
int val;
node next;
node(int x) {
val = x;
next = null;
}
}
public class prblm237 {
public static void main(String[] args) {
//Self Made LinkedList to check the code
node l1 = new node(4);
node l2 = new node(5);
node l3 = new node(1);
node l4 = new node(9);
node head = l1;
node node = l2;
l1.next = l2;
l2.next = l3;
l3.next = l4;
printNode(head);
deleteNode(node);
printNode(head);
}
public static void deleteNode(node node) {
node.val = node.next.val;
node.next = node.next.next;
}
public static void printNode(node head){
node curr = head;
while (curr != null) {
System.out.print(curr.val + " ");
curr = curr.next;
}
System.out.println();
}
}