Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1a.

) java program to create a singly linked list with some node containing names of cities in Nepal
and display all elements of list..

=
class Node{

String data;

Node next;

class SinglyLinkedList

{ Node head;

SinglyLinkedList(Node head)

this.head=head;

public class Main

public static void main (String args[])

Node n1=new Node();

Node n2=new Node();

Node n3=new Node();

Node n4=new Node();

n1.data="Kathmandu";

n2.data="lalitpur";

n3.data="Bhaktapur";

n4.data="Dolakha";
n1.next=n2;

n2.next=n3;

n3.next=n4;

n4.next=null;

SinglyLinkedList au= new SinglyLinkedList(n1);

Node tempHead= au.head;

while(tempHead!=null)

System.out.println(tempHead.data);

tempHead=tempHead.next;

System.out.println("\nlab no:1a\nName:Anurag\nRollno:18000-36");

You might also like