Project

General

Profile

Statistics
| Revision:

root / proj / libs / classes / src / queue.c @ 339

History | View | Annotate | Download (864 Bytes)

1 277 up20180642
#include <lcom/lcf.h>
2
3
#include "queue.h"
4
5
#include "list.h"
6
#include "errors.h"
7
8
struct queue{
9
    list_t *l;
10
};
11
12
queue_t* (queue_ctor )(void){
13
    queue_t *ret = malloc(sizeof(queue_t));
14
    if(ret == NULL) return NULL;
15
    ret->l = list_ctor();
16
    if(ret->l == NULL){
17
        queue_dtor(ret);
18
        return NULL;
19
    }
20
    return ret;
21
}
22
int      (queue_dtor )(queue_t *q){
23
    int r;
24
    if((r = list_dtor(q->l))) return r;
25
    free(q);
26
    return SUCCESS;
27
}
28
size_t   (queue_size )(const queue_t *q           ){ return list_size (q->l); }
29
int      (queue_empty)(const queue_t *q           ){ return list_empty(q->l); }
30
void     (queue_push )(      queue_t *q, void *val){ list_push_back(q->l, val); }
31
void*    (queue_top  )(const queue_t *q           ){ return *list_front(q->l); }
32
void     (queue_pop  )(      queue_t *q           ){ list_pop_front(q->l); }