forked from sanketpatil02/Code-Overflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteEvenPosEle_Stack.c
More file actions
85 lines (79 loc) · 1.09 KB
/
DeleteEvenPosEle_Stack.c
File metadata and controls
85 lines (79 loc) · 1.09 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
using namespace std;
int pop(int stack[],int *top,int size)
{
if( *top==-1)
printf("\nStack is empty!!");
else
{
int m;
m=stack[*top];
*top=*top-1;
return m;
}
}
void push(int val,int stack[],int *top,int size)
{
if(*top==size-1)
{
printf("\nStack is full");
}
else
{
*top=*top+1;
stack[*top]=val;
}
}
void display(int stack[],int *top)
{
int i;
printf("Stack\n");
if(*top==-1)
{
printf("\nStack is empty");
}
else
{
for( int i=*top;i>=0;--i)
printf("%d\n",stack[i]);
}
}
bool emp(int *top)
{
if(*top==-1)
return 1;
else
return 0;
}
int main()
{
int val,m,s1[10],s2[10],t1=-1,t2=-1,size;
printf("Enter the size of stack : ");
scanf("%d",&size);
printf("\nEnter element to push : \n");
for(int i=1;i<=size;i++)
{
scanf("%d",&val);
push(val,s1,&t1,size);
}
display(s1,&t1);
while(!emp(&t1))
{
if(t1%2==0)
{
pop(s1,&t1,size);
}
else
{
m=pop(s1,&t1,size);
push(m,s2,&t2,size);
}
}
while(!emp(&t2))
{
m=pop(s2,&t2,size);
push(m,s1,&t1,size);
}
printf("After Deleting Even position elements from Stack:\n");
display(s1,&t1);
}