#include “stack.h”
#include “refcount.h”
#include
struct stack s1;
struct stack s2;
void push(int i) {
int *p = rc_malloc(sizeof(int));
*p = i;
if(i % 3 == 0) {
rc_keep_ref(p);
stack_push(&s1, p);
}
if(i % 5 == 0) {
rc_keep_ref(p);
stack_push(&s2, p);
}
rc_free_ref(p);
}
void print_and_clear(struct stack *s) {
while(1) {
int *p = stack_pop(s);
if(p == NULL)
break;
printf(“%d “, *p);
rc_free_ref(p);
}
printf(“\n”);
}
int main() {
stack_init(&s1);
stack_init(&s2);
for(int i=0; i<30; i++) {
push(i);
}
print_and_clear(&s1);
print_and_clear(&s2);
}