Data Structure - Interview Questions and Answers for 'Delete' - 3 question(s) found - Order By Newest Ans. public class LinkedList {
Node start = null;
Node head = null;
class Node {
Integer body;
Node nextNode;
Node(Integer value) {
body = value;
}
}
private void addNodeToEnd(Integer value) {
if (start == null) {
start = new Node(value);
head = start;
head.nextNode = null;
return;
}
while (head.nextNode != null) {
head = head.nextNode;
}
head.nextNode = new Node(value);
}
private void deleteNode(Integer value) {
head = start;
while (head.nextNode != null) {
if(head.nextNode.body == value){
head.nextNode = head.nextNode.nextNode;
}
head = head.nextNode;
}
}
private void traverse() {
head = start;
while (head != null) {
System.out.println(head.body);
head = head.nextNode;
}
}
public static void main(String[] args) {
LinkedList ll = new LinkedList();
ll.addNodeToEnd(5);
ll.addNodeToEnd(10);
ll.addNodeToEnd(15);
ll.traverse();
ll.deleteNode(10);
ll.traverse();
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  linkedlist  delete node from linkedlistRelated Questions What is the difference between ArrayList and LinkedList ? If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ? In a Linked list with sorted numbers, insert a new numbers while maintaining the sort order. Is this a valid initialization ? Explain.
Collection<Collection> collection = new LinkedList<LinkedList>(); Difference between ArrayList and LinkedList ? Find the third last element in a linked list ? Write a program for LinkedList, with method to append node and traversing the list ? Difference between List and LinkedList ? Is it legal to initialize List like this ? Ans. No, delete is not a keyword in Java. Destruction of objects is taken care by Java Garbage Collection mechanism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  delete  keywords Asked in 1 Companies Related Questions What are the common uses of "this" keyword in java ? Which of the following combination of keywords is illegal in Java ?
a. static and transient
b. transient and final
c. static and synchronized
d. abstract and final Which keyword is used to provide explicit access of a code block to single thread ?
a. Transient
b. Final
c. Explicit
d. Synchronized How does volatile affect code optimization by compiler? What is Volatile keyword used for ? What is the use of Transient Keyword ? Can we access instance variables within static methods ? When we say final x = 10, is the reference final or the value ? What is a Final Method ? What is a Final Class ? This question was recently asked at 'Caprus IT'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  linkedlist  delete a node from linked list Asked in 1 Companies Related Questions What is the difference between ArrayList and LinkedList ? If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ? In a Linked list with sorted numbers, insert a new numbers while maintaining the sort order. Is this a valid initialization ? Explain.
Collection<Collection> collection = new LinkedList<LinkedList>(); Difference between ArrayList and LinkedList ? Find the third last element in a linked list ? Write a program for LinkedList, with method to append node and traversing the list ? Write method to delete Node from a LinkedList. Difference between List and LinkedList ? Is it legal to initialize List like this ?