#include <stdio.h>
#include <stdlib.h>
#include"container.h"

typedef struct elem{int id;}elem_t;

elem_t *create_elem(int i){
    elem_t * e = (elem_t*)malloc(sizeof(elem_t));
    e->id = i;
    return e;
}

int compare(void *e1, void *e2){
    elem_t * elem1 = (elem_t*)elem1;
    elem_t * elem2 = (elem_t*)elem2;

    if (elem1->id > elem2->id){
        return 1;
    }
    else if (elem1->id < elem2->id){
        return -1;
    }
    else{
        return 0;
    }
}

void print(void *e){
    elem_t * elem = (elem_t*)e;
    printf("%d",elem->id);
}

void * copy(void *e){
    if (!e) return NULL;

    elem_t * elem = (elem_t*)malloc(sizeof(elem_t*));
    elem_t * elem_aux = (elem_t*)e;
    elem->id = elem_aux->id;
    return (void*)elem;
}


int main()
{

    container_t * c = create(compare,copy);

    for (int i=0;i<10;i++){
        _push_back(c,create_elem(i));
    }

    container_t * cp = duplicate(c);

    visit(cp,print);


    return 0;
}
