SlideShare a Scribd company logo
1 of 7
Download to read offline
LinkedListOperations.java:-
class Node
{
public int item;
public Node next;
public Node(int val)
{
item = val;
}
public void displayNode()
{
System.out.println("[" + item + "] ");
}
}
class LinkedList
{
private Node first;
public LinkedList()
{
first = null;
}
public boolean isEmpty()
{
return (first==null);
}
public void insert(int val)//inserts at beginning of list
{
Node newNode = new Node(val);
newNode.next = first;
first = newNode;
}
public Node delete()//deletes at beginning of list
{
Node temp = first;
first = first.next;
return temp;
}
public void display()
{
System.out.println("List items from first to last :");
Node current = first;
while(current != null)
{
current.displayNode();
current = current.next;
}
System.out.println("");
}
public Node search(int val)
{
Node current = first;
while(current.item != val)
{
if(current.next == null)
return null;
else
current = current.next;
}
return current;
}
public Node delete(int val)
{
Node current = first;
Node previous = first;
while(current.item != val)
{
if(current.next == null)
return null;
else
{
previous = current;
current = current.next;
}
}
if(current == first)
first = first.next;
else
previous.next = current.next;
return current;
}
}
class LinkedListOperations
{
public static void main(String[] args)
{
LinkedList object = new LinkedList();
object.insert(10);
object.insert(20);
object.insert(30);
object.display();
while( !object.isEmpty() )
{
Node member = object.delete();
System.out.print("Deleted ");
member.displayNode();
System.out.println("");
}
object.display();
object.insert(40);
object.insert(50);
object.insert(60);
object.display();
Node objecttosearch = object.search(50);
if( objecttosearch != null)
System.out.println("Found Node : " + objecttosearch.item);
else
System.out.println("Cannot locate the node");
Node objecttodelete = object.delete(50);
if( objecttodelete != null )
System.out.println("Deleted node : " + objecttodelete.item);
else
System.out.println("Cannot delete the node");
object.display();
}
}
Solution
LinkedListOperations.java:-
class Node
{
public int item;
public Node next;
public Node(int val)
{
item = val;
}
public void displayNode()
{
System.out.println("[" + item + "] ");
}
}
class LinkedList
{
private Node first;
public LinkedList()
{
first = null;
}
public boolean isEmpty()
{
return (first==null);
}
public void insert(int val)//inserts at beginning of list
{
Node newNode = new Node(val);
newNode.next = first;
first = newNode;
}
public Node delete()//deletes at beginning of list
{
Node temp = first;
first = first.next;
return temp;
}
public void display()
{
System.out.println("List items from first to last :");
Node current = first;
while(current != null)
{
current.displayNode();
current = current.next;
}
System.out.println("");
}
public Node search(int val)
{
Node current = first;
while(current.item != val)
{
if(current.next == null)
return null;
else
current = current.next;
}
return current;
}
public Node delete(int val)
{
Node current = first;
Node previous = first;
while(current.item != val)
{
if(current.next == null)
return null;
else
{
previous = current;
current = current.next;
}
}
if(current == first)
first = first.next;
else
previous.next = current.next;
return current;
}
}
class LinkedListOperations
{
public static void main(String[] args)
{
LinkedList object = new LinkedList();
object.insert(10);
object.insert(20);
object.insert(30);
object.display();
while( !object.isEmpty() )
{
Node member = object.delete();
System.out.print("Deleted ");
member.displayNode();
System.out.println("");
}
object.display();
object.insert(40);
object.insert(50);
object.insert(60);
object.display();
Node objecttosearch = object.search(50);
if( objecttosearch != null)
System.out.println("Found Node : " + objecttosearch.item);
else
System.out.println("Cannot locate the node");
Node objecttodelete = object.delete(50);
if( objecttodelete != null )
System.out.println("Deleted node : " + objecttodelete.item);
else
System.out.println("Cannot delete the node");
object.display();
}
}

More Related Content

Similar to LinkedListOperations.java-class Node{    public int item;  .pdf

PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdfharihelectronicspune
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdfAKVIGFOEU
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdffunkybabyindia
 
Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdfaravlitraders2012
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdfKUNALHARCHANDANI1
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timekarianneberg
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfapoorvikamobileworld
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfbirajdar2
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdffootstatus
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
Link list part 2
Link list part 2Link list part 2
Link list part 2Anaya Zafar
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 

Similar to LinkedListOperations.java-class Node{    public int item;  .pdf (20)

PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdf
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
 
Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdf
 
In the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdfIn the class we extensively discussed a generic singly linked list i.pdf
In the class we extensively discussed a generic singly linked list i.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 

More from aquastore223

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdfaquastore223
 
c++ code for a Median of Integer Stream from Text File program#.pdf
 c++ code for a Median of Integer Stream from Text File program#.pdf c++ code for a Median of Integer Stream from Text File program#.pdf
c++ code for a Median of Integer Stream from Text File program#.pdfaquastore223
 
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdfaquastore223
 
the hybridisation is sp2 since the electron cloud.pdf
                     the hybridisation is sp2 since the electron cloud.pdf                     the hybridisation is sp2 since the electron cloud.pdf
the hybridisation is sp2 since the electron cloud.pdfaquastore223
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdfaquastore223
 
Hydrocrbon is the organic compound which containing only the atoms .pdf
   Hydrocrbon is the organic compound which containing only the atoms .pdf   Hydrocrbon is the organic compound which containing only the atoms .pdf
Hydrocrbon is the organic compound which containing only the atoms .pdfaquastore223
 
No. In order for a substance to conduct electrici.pdf
                     No. In order for a substance to conduct electrici.pdf                     No. In order for a substance to conduct electrici.pdf
No. In order for a substance to conduct electrici.pdfaquastore223
 
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf
HCHO OS for H is +1, O is -2 there are two Hs o.pdfaquastore223
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdfaquastore223
 
The electrons reach or give off a certain amount of energy and diffe.pdf
  The electrons reach or give off a certain amount of energy and diffe.pdf  The electrons reach or give off a certain amount of energy and diffe.pdf
The electrons reach or give off a certain amount of energy and diffe.pdfaquastore223
 
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdfWeak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdfaquastore223
 
var min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdfvar min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdfaquastore223
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfaquastore223
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfaquastore223
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdfaquastore223
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfaquastore223
 
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdfThe answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdfaquastore223
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfaquastore223
 
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdfThe answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdfaquastore223
 
SolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdfSolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdfaquastore223
 

More from aquastore223 (20)

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf
 
c++ code for a Median of Integer Stream from Text File program#.pdf
 c++ code for a Median of Integer Stream from Text File program#.pdf c++ code for a Median of Integer Stream from Text File program#.pdf
c++ code for a Median of Integer Stream from Text File program#.pdf
 
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
 
the hybridisation is sp2 since the electron cloud.pdf
                     the hybridisation is sp2 since the electron cloud.pdf                     the hybridisation is sp2 since the electron cloud.pdf
the hybridisation is sp2 since the electron cloud.pdf
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdf
 
Hydrocrbon is the organic compound which containing only the atoms .pdf
   Hydrocrbon is the organic compound which containing only the atoms .pdf   Hydrocrbon is the organic compound which containing only the atoms .pdf
Hydrocrbon is the organic compound which containing only the atoms .pdf
 
No. In order for a substance to conduct electrici.pdf
                     No. In order for a substance to conduct electrici.pdf                     No. In order for a substance to conduct electrici.pdf
No. In order for a substance to conduct electrici.pdf
 
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdf
 
The electrons reach or give off a certain amount of energy and diffe.pdf
  The electrons reach or give off a certain amount of energy and diffe.pdf  The electrons reach or give off a certain amount of energy and diffe.pdf
The electrons reach or give off a certain amount of energy and diffe.pdf
 
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdfWeak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
 
var min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdfvar min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdf
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdf
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdf
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdf
 
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdfThe answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
 
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdfThe answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
 
SolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdfSolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 

Recently uploaded (20)

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 

LinkedListOperations.java-class Node{    public int item;  .pdf

  • 1. LinkedListOperations.java:- class Node { public int item; public Node next; public Node(int val) { item = val; } public void displayNode() { System.out.println("[" + item + "] "); } } class LinkedList { private Node first; public LinkedList() { first = null; } public boolean isEmpty() { return (first==null); } public void insert(int val)//inserts at beginning of list { Node newNode = new Node(val); newNode.next = first; first = newNode; } public Node delete()//deletes at beginning of list { Node temp = first; first = first.next;
  • 2. return temp; } public void display() { System.out.println("List items from first to last :"); Node current = first; while(current != null) { current.displayNode(); current = current.next; } System.out.println(""); } public Node search(int val) { Node current = first; while(current.item != val) { if(current.next == null) return null; else current = current.next; } return current; } public Node delete(int val) { Node current = first; Node previous = first; while(current.item != val) { if(current.next == null) return null; else { previous = current;
  • 3. current = current.next; } } if(current == first) first = first.next; else previous.next = current.next; return current; } } class LinkedListOperations { public static void main(String[] args) { LinkedList object = new LinkedList(); object.insert(10); object.insert(20); object.insert(30); object.display(); while( !object.isEmpty() ) { Node member = object.delete(); System.out.print("Deleted "); member.displayNode(); System.out.println(""); } object.display(); object.insert(40); object.insert(50); object.insert(60); object.display(); Node objecttosearch = object.search(50); if( objecttosearch != null)
  • 4. System.out.println("Found Node : " + objecttosearch.item); else System.out.println("Cannot locate the node"); Node objecttodelete = object.delete(50); if( objecttodelete != null ) System.out.println("Deleted node : " + objecttodelete.item); else System.out.println("Cannot delete the node"); object.display(); } } Solution LinkedListOperations.java:- class Node { public int item; public Node next; public Node(int val) { item = val; } public void displayNode() { System.out.println("[" + item + "] "); } } class LinkedList { private Node first; public LinkedList() { first = null; }
  • 5. public boolean isEmpty() { return (first==null); } public void insert(int val)//inserts at beginning of list { Node newNode = new Node(val); newNode.next = first; first = newNode; } public Node delete()//deletes at beginning of list { Node temp = first; first = first.next; return temp; } public void display() { System.out.println("List items from first to last :"); Node current = first; while(current != null) { current.displayNode(); current = current.next; } System.out.println(""); } public Node search(int val) { Node current = first; while(current.item != val) { if(current.next == null) return null; else current = current.next;
  • 6. } return current; } public Node delete(int val) { Node current = first; Node previous = first; while(current.item != val) { if(current.next == null) return null; else { previous = current; current = current.next; } } if(current == first) first = first.next; else previous.next = current.next; return current; } } class LinkedListOperations { public static void main(String[] args) { LinkedList object = new LinkedList(); object.insert(10); object.insert(20); object.insert(30); object.display(); while( !object.isEmpty() )
  • 7. { Node member = object.delete(); System.out.print("Deleted "); member.displayNode(); System.out.println(""); } object.display(); object.insert(40); object.insert(50); object.insert(60); object.display(); Node objecttosearch = object.search(50); if( objecttosearch != null) System.out.println("Found Node : " + objecttosearch.item); else System.out.println("Cannot locate the node"); Node objecttodelete = object.delete(50); if( objecttodelete != null ) System.out.println("Deleted node : " + objecttodelete.item); else System.out.println("Cannot delete the node"); object.display(); } }