Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
linkl
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.io.*; import java.util.*; import java.lang.*; public class LinkedList { // static class LinkedList{ Node head; static class Node{ int data; Node next; Node(int data){ this.data = data; next = null; } } public static void delete(int position){ if(head==null) return; Node temp = head; Node prev = null; for(int i=0; temp!=null && i<position;i++){ prev = temp; temp = temp.next; } prev.next = temp.next; } public static void print(){ Node temp = head; while(temp!=null){ System.out.print(temp.data+" "); temp = temp.next; } } public static void main(String args[]) { LinkedList ll = new LinkedList(); ll.head = new Node(1); Node second = new Node(2); ll.head.next = second; Node third = new Node(3); second.next = third; Node fourth = new Node(4); third.next = fourth; delete(3); print(); } // } }
run
|
edit
|
history
|
help
0
Vikas
Day
add2
pass
4th ques
1D
String reverse
Piramid
Symmetric Tree
apple1