-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueueustack.c
More file actions
61 lines (59 loc) · 828 Bytes
/
Copy pathqueueustack.c
File metadata and controls
61 lines (59 loc) · 828 Bytes
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
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
//struct node *stack1=NULL;
//struct node *stack2=NULL;
void push(struct node **s,int x) //insert at front 1st addrss is always NULL
{
struct node *nn=(struct node*)malloc(sizeof(struct node));
nn->data=x;
nn->next=*s;
*s=nn;
}
int pop(struct node **s )
{
int res;
while(*s)
{
struct node *temp;
temp=*s;
res=(temp)->data;
*s=temp->next;
free(temp);
return res;
}
}
void en(struct node **s,int x)
{
push(s,x);
}
int de(struct node **s1,struct node **s2)
{
int r,x;
if(*s2==NULL)
{
while(*s1!=NULL)
{
r=pop(s1);
push(s2,r);
}
}
x=pop(s2);
return x;
}
int main()
{
struct node *stack1=NULL;
struct node *stack2=NULL;
en (&stack1,8);
en(&stack1,1);
en(&stack1,2);
en(&stack1,3);
int p=de(&stack1,&stack2);
printf("%d",p);
return 0;
}