-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStack_DLL.java
More file actions
61 lines (57 loc) · 1.13 KB
/
Stack_DLL.java
File metadata and controls
61 lines (57 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*Created by Sidhant
21/04/17*/
//Implements stack using double linked list
import java.util.*;
class node
{
int val;
node next;
node prev;
}
public class Stack_DLL
{
public static void main (String args[])
{
Scanner in=new Scanner (System.in);
int flag=0;node head=null,a,b=null;
while(true)
{
System.out.println("1-insert\n2-delete\n3-print\n4-break");
int d=in.nextInt();
if (d==1)
{
flag++;
System.out.println("Enter Data");
a=new node();
a.val=in.nextInt();
a.next=null;
a.prev=null;
if (flag==1)
head=a;
else
{
b.next=a;
a.prev=b;
}
b=a;
}
if (d==2)
{
b=b.prev;
b.next=null;
}
if(d==3)
{
a=head;
while(a!=null)
{
System.out.print(a.val+" ");
a=a.next;
}
System.out.println();
}
if (d==4)
break;
}
}
}