#include <stdio.h>
#include <stdlib.h>
#define N 10
#define M 5
#include "kernel_list.h"
struct people{
int element;
struct head_list list;
};
typedef struct people people_t;
int main(int argc, const char *argv[])
{
struct head_list h = {&h, &h};
struct head_list * l, *tmp;
people_t * t;
int i;
int c = 1;
for(i = 0; i < N; i++){
t = malloc(sizeof(*t));
t->element = N - i;
list_add(&t->list, &h);
}
//l = (&h)->next->next;
//list_delete(l->pre, l->next);
l = (&h)->next;
while(1){
if(l == &h)
break;
printf("%d ", container_of(l, people_t, list)->element);
l = l->next;
}
printf("\n");
l = (&h)->next;
while((&h)->next != (&h)){
l = l->next;
if(l != (&h))
c++;
if(c == M){
tmp = l->next;
list_delete(l->pre, l->next);
printf("%d ", container_of(l, people_t, list)->element);
free(container_of(l, people_t, list));
l = tmp;
if(l == &h)
l = l->next;
c = 1;
}
}
printf("\n");
return 0;
}