/**
DoubleLinkedlist.java: This program demonstrate How to create Double linked Node in java.
Author:itsafiz@gmail.com
*/
import java.util.*;
class Node // Node class
{
int data; // data field
Node next; // address
Node pre; // address
Node(int data)
{
this.data=data;
next=null;
pre=null;
}
}
class DoubleLinkedlist
{
public static void main(String[]args)
{
int c,d;
Node start=null,head=null;
Scanner in = new Scanner(System.in);
while(true)
{
System.out.println("1.Insert\n2.Display \n3.Exit\n");
c=in.nextInt();
switch(c)
{
case 1:
System.out.println("Enter Element");
d = in.nextInt();
Node temp = new Node(d);//
if(head==null){
head=temp;
start=head;}
else{
head.next= temp;
temp.pre=head;
head=temp;
}
break;
case 2:
for(temp = start; temp!=null;temp=temp.next)
System.out.print(temp.data);
System.out.println();
break;
default: System.exit(0);
}
}
}
}
2 Comments
this is rubbish example
ReplyDeleteHeello nice post
ReplyDelete