java program to delete the linked list elements from a singly

Solutions on MaxInterview for java program to delete the linked list elements from a singly by the best coders in the world

showing results for - "java program to delete the linked list elements from a singly"
Bryan
16 Jul 2017
1public class Main{ class Node{ int data; Node next; public Node(int data) { this.data = data; this.next = null; } } public Node first = null; public Node last = null; public void addNode(int data){ Node newNode = new Node(data); if(first == null) { first = newNode; last = newNode; } else { last.next = newNode; last = newNode; } } public void deleteFromStart(){ if(first == null) { System.out.println("List is empty"); return; } else { if(first != last) { first = first.next; } else { first = last = null; } } } public void display() { Node current = first; if(first == null) { System.out.println("List is empty"); return; } while(current != null) {System.out.print(current.data + " "); current = current.next; } System.out.println(); } public static void main(String[] args) { Main sList = new Main(); sList.addNode(2); sList.addNode(4); sList.addNode(6); sList.addNode(8); System.out.println("Original List"); sList.display(); while(sList.first != null) { sList.deleteFromStart(); System.out.println("After list element deleted"); sList.display(); } } } 
queries leading to this page
delete from linked list javalinked list delete javadelete a particular data in linked list in javajava linkedlist deletionhow to delete the whole singly linked list in javaremove all elements from linked list javadelete node in a linked list javalinked list deletion code in javaremove an element from linkedlist javahow to remove stuff from a linked list in javadelete linked list javahow to remove an element from linked list javamethod to remove all elements from a linked list in javahow to delete a node in linked list javalinked list deletion at ending in javahow to delete a linked list completely javalinked list remove javahow to delete from linked list javadelete a node from linked list in javadelete element from linked list javaremove an item from linked list java with out using librarydelete method in linked list javaremove from a linked list javadelete node in a linked list in javahow to remove item from linked list javahow to remove a node from a linked list javalinked list program in java delete a noderemove an item from linked list java without using librarydelet an element from linked list in javaremove item from linked list javaalgo to delete linked list in javadelete a node in java linked listdlete node in linkedlist in javadeletion in linked list javahow to delete element from the end of the singly linked list using javadelete node in linked list javaremove linked list elements javadeleting an element from linked list javahow to implement a delete tail in a linked list javaremove the elements from linkedlist in javacan you remove all elements from a linked list javadelete all elements from doubky linked list in javadeletelast single linked list implementation in javahow to remove an element from a linkedlist javawrite remove method from linked list javaremove an element from linked list javahow to delete a node in linked list in javahow to delete an element in linked list javahow to remove elements from linked list in java 3fremove element linked list javadelete all elements from doubly linked list in javaremove element method from linked list javadeletion of linked list in javaremove linked list javalinked list delete java utildelete an element in linked list javajava remove item from linked listremove element from linkedlist javadelete elemnet from linked list javaremove element from linked list javahow to remove from your linked list javadeletion of node in linked list in javajava program to delete the linked list elements from a singly