How to make linked list program for the given list ?

  • Linked List is a type of Linear Data Structure that is mostly used data structure after array, which allocates memory dynamically at run time that is it doesn’t require any size initialization as in case of array.
  • Linked List stores data in the forms of nodes, which is divided into two parts, first part stores the data and second part points to the next node by storing the address of that node.
  • We have first node which contains Data and Address to next node, and similarly second and third node forming a chain.
Linked List in Data Structure

Syntax

  • To create code, pattern required is:
LinkedList<String> linkedList=new LinkedList<String>()

Sample Code in Java

import java.util.Iterator;

import java.util.LinkedList;

public class LinkedListDemo
{

public static void main (String[] args) {

LinkedList<String> linkedList=new LinkedList<String>();

linkedList.add("java");

linkedList.add("Is");

linkedList.add("High");

linkedList.add("Level");

linkedList.add("Language");

Iterator<String> itr=linkedList.iterator();

while(itr.hasNext())
{

System.out.print(itr.next());

System.out.print("\t");

}

}

}

Output

java Is High Level Language

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,