We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a2128a1 commit 7ae686aCopy full SHA for 7ae686a
C Program for stack operations using array
@@ -0,0 +1,49 @@
1
+#include<stdio.h>
2
+
3
+#define MAX_SIZE 101
4
5
+int A[MAX_SIZE];
6
+int top = -1;
7
+void Push(int x)
8
+{
9
+ if(top == MAX_SIZE -1)
10
+ {
11
+ printf("Error: stack overflow\n");
12
+ return;
13
+ }
14
+ A[++top] = x;
15
+}
16
+void Pop()
17
18
+ if(top == -1)
19
20
+ printf("Error: No element to pop\n");
21
22
23
+ top--;
24
25
+int Top()
26
27
+ return A[top];
28
29
+int IsEmpty()
30
31
+ if(top == -1) return 1;
32
+ return 0;
33
34
+void Print() {
35
+ int i;
36
+ printf("Stack: ");
37
+ for(i = 0;i<=top;i++)
38
+ printf("%d ",A[i]);
39
+ printf("\n");
40
41
42
+int main()
43
44
+ Push(12);Print();
45
+ Push(6);Print();
46
+ Push(10);Print();
47
+ Pop();Print();
48
+ Push(8);Print();
49
0 commit comments