Skip to content

Commit 77601d6

Browse files
committed
Create stack
1 parent d7d5487 commit 77601d6

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

stack

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include<stdio.h>
2+
#include<conio.h>
3+
#include<stdlib.h>
4+
#define MAX 10
5+
#define MAXX 100
6+
int stack[MAX];
7+
int top=-1;
8+
int stack1[MAXX];
9+
int top1=-1;
10+
int i=0;
11+
void push(int);
12+
void push1(int,int);
13+
void pop();
14+
void main()
15+
{
16+
int j,ch,prev;
17+
clrscr();
18+
do
19+
{
20+
printf("\nenter 1 the to push element");
21+
printf("\nenter 2 to pop the element");
22+
printf("\nente 3 to exit");
23+
printf("\nenter your choice");
24+
scanf("%d",&ch);
25+
switch(ch)
26+
{
27+
case 1:
28+
{
29+
30+
push(i);
31+
i++;
32+
break;
33+
}
34+
case 2:
35+
{
36+
pop();
37+
break;
38+
}
39+
case 3:
40+
exit(0);
41+
default:
42+
printf("\nplease enter valid choice");
43+
}
44+
}
45+
while(1);
46+
}
47+
void push(int i)
48+
{
49+
50+
while(i<10)
51+
{
52+
53+
if(top==MAX-1)
54+
{
55+
printf("stack is full\n");
56+
}
57+
58+
top++;
59+
stack[top]=i;
60+
printf("\nitem is pushed %d",i);
61+
62+
break;
63+
}
64+
65+
}
66+
67+
68+
69+
void push1(int prev,int temp)
70+
{
71+
int j,t2;
72+
top1++;
73+
t2=prev-stack1[top1];
74+
stack1[top1]=prev;
75+
printf("\nitem %d",prev);
76+
if(top1==MAXX-1)
77+
{
78+
printf("\nStack is full");
79+
}
80+
if(temp!=0 && temp!=1 && temp!=-1 && t2!=1 && t2!=-1 && t2!=0)
81+
{
82+
printf("\nstring is invalid");
83+
}
84+
85+
}
86+
void pop()
87+
{
88+
int i,temp,t1,prev;
89+
if(top==-1)
90+
{
91+
printf("\nstack is empty");
92+
return;
93+
}
94+
i=stack[top];
95+
prev=i;
96+
printf("\nitem poped=%d",i);
97+
t1=stack[top-1];
98+
top--;
99+
temp=i-t1;
100+
push1(prev,temp);
101+
102+
}
103+

0 commit comments

Comments
 (0)