forked from kosmos30732/Data-Structures
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_queue.c
More file actions
Latest commit
43 lines (38 loc) · 723 Bytes
/
Copy pathstack_queue.c
File metadata and controls
43 lines (38 loc) · 723 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
//
// Created by slaventy on 04.07.2020.
//
#include"stack.h"
#include<stdio.h>
structstack_queue
{
stacka;
stackb;
};
structstack_queuestack_queue_new()
{
structstack_queuequeue=
{
.a=stack_new(),
.b=stack_new()
};
returnqueue;
}
intstack_queue_pop(structstack_queues)
{
if(stack_is_empty(s.b))
{
while (!stack_is_empty(s.a))
{
stack_push(s.b, stack_pop(s.a));
}
}
returnstack_pop(s.b);
}
voidstack_queue_push(structstack_queuequeue, inta)
{
stack_push(queue.a, a);
}
intstack_queue_len(structstack_queues)
{
returnstack_len(s.a) +stack_len(s.b);
}