-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProblem-3.java
56 lines (39 loc) · 998 Bytes
/
Problem-3.java
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
/**
* @author AkashGoyal
*/
/**
--------------------- Problem----------->> Implement Stack using Linked List
Problem Link :- https://practice.geeksforgeeks.org/problems/implement-stack-using-linked-list/1
Reference: -https://www.youtube.com/watch?v=MuwxQ2IB8lQ
*/
class MyStack
{
StackNode top;
//Function to push an integer into the stack.
void push(int a)
{
// Add your code here
StackNode node=new StackNode(a);
if(top==null)
{
top=node;
}
else
{
node.next=top;
top=node;
}
}
//Function to remove an item from top of the stack.
int pop()
{
// Add your code here
if(top==null)
{
return -1;
}
int data=top.data;
top=top.next;
return data;
}
}