We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dd0a090 commit 34d30edCopy full SHA for 34d30ed
1 file changed
Stack/Stack_LL.java
@@ -0,0 +1,50 @@
1
+public class Stack_LL
2
+{
3
+ class Node
4
+ {
5
+ Node next;
6
+ int data;
7
+ public Node(int d)
8
9
+ next=null;
10
+ data=d;
11
+ }
12
13
+ Node head;
14
+ public void push(int d)
15
16
+ Node newNode=new Node(d);
17
+ newNode.next=head;
18
+ head=newNode;
19
20
+ public void display()
21
22
+ Node n=head;
23
+ while(n!=null)
24
25
+ System.out.println(n.data);
26
+ n=n.next;
27
28
29
+ public int pop()
30
31
+ Node temp=head;
32
+ head=head.next;
33
+ return temp.data;
34
35
+ public static void main(String args[])
36
37
+ Stack_LL s = new Stack_LL();
38
+ s.push(1);
39
+ s.push(2);
40
+ s.push(3);
41
+ s.push(4);
42
+ s.push(5);
43
+ int x= s.pop();
44
+ System.out.println("Element popped is "+x);
45
+ int y = s.pop();
46
+ System.out.println("Element popped is "+y);
47
+ s.display();
48
49
+
50
+}
0 commit comments