Skip to content

Commit aec1aa2

Browse files
committed
stack
1 parent 8efbc13 commit aec1aa2

8 files changed

Lines changed: 83 additions & 8 deletions

File tree

.idea/workspace.xml

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Queue/queue.java

Whitespace-only changes.

Stack/Stack.class

75 Bytes
Binary file not shown.

Stack/stackLinked$Node.class

421 Bytes
Binary file not shown.

Stack/stackLinked.class

1.51 KB
Binary file not shown.

Stack/stackLinked.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import java.util.*;
2+
3+
public class stackLinked
4+
{
5+
Node root;
6+
public class Node
7+
{
8+
int data;
9+
Node next;
10+
Node(int data)
11+
{
12+
this.data=data;
13+
//this.next=null;
14+
}
15+
16+
}
17+
public void push(int data)
18+
{
19+
Node newNode=new Node(data);
20+
21+
if(root==null)
22+
{
23+
root=newNode;
24+
}
25+
else
26+
{
27+
Node temp=root;
28+
root=newNode;
29+
newNode.next=temp;
30+
}
31+
System.out.println(data+" pushed to stack");
32+
33+
34+
}
35+
public boolean isEmpty()
36+
{
37+
if(root==null)
38+
{
39+
return true;
40+
}
41+
else
42+
return false;
43+
}
44+
public int pop()
45+
{
46+
int popped=Integer.MIN_VALUE;
47+
if(root==null)
48+
{
49+
System.out.println("Stack is empty");
50+
}
51+
else
52+
{
53+
popped=root.data;
54+
root=root.next;
55+
}
56+
return popped;
57+
}
58+
59+
60+
61+
public static void main(String args[])
62+
{
63+
stackLinked s=new stackLinked();
64+
s.push(3);
65+
s.push(4);
66+
int x=s.pop();
67+
System.out.println(x+ " popped");
68+
69+
70+
71+
}
72+
}

Stack/stackop.class

10 Bytes
Binary file not shown.

Stack/stackop.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ class Stack
99
}
1010
void push(int data)
1111
{
12+
if(top>=capacity-1)
13+
{
14+
System.out.println("Stack is full");
15+
}
16+
else
17+
{
1218
top++;
1319
arr[top]=data;
1420
System.out.println(arr[top]+" Item pushed");
21+
}
1522
}
1623

1724

@@ -28,6 +35,7 @@ public static void main(String[] args) {
2835
s.push(6);
2936
s.push(7);
3037
s.push(8);
38+
s.push(9);
3139
}
3240

3341

0 commit comments

Comments
 (0)