Ejemplo n.º 1
0
static void remove_tail(SR_RefList *tail) //recursive function to remove tail of list.
{
  if (tail->older != NULL)
    remove_tail(tail->older);
    
  free(tail);
}
inline HeapRegion* FreeRegionList::remove_tail_or_null() {
  check_mt_safety();

  if (!is_empty()) {
    return remove_tail();
  } else {
    return NULL;
  }
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
	printf("\n");
	/*
	 * testing the creation of lists and appending
	 */
	printf("%s\n\n", "Commands Test 1");
	LTICKET ref = create_list("Adewale");
	append_to_list(ref, "Olufemi");
	append_to_list(ref, "Nneka");
	append_to_list(ref, "Jacob");
	append_to_list(ref, "Adetola");
	append_to_list(ref, "Kemi");
	visit_nodes(ref);
	delete_list(ref);

	/*
	 * testing the head and tail removal as well as head insertion
	 */
	printf("%s\n\n", "Commands Test 2");
	LTICKET ref2 = create_list("Adewale");
	append_to_list(ref2, "Olufemi");
	append_to_list(ref2, "Nneka");
	append_to_list(ref2, "Jacob");
	append_to_list(ref2, "Adetola");
	append_to_list(ref2, "Kemi");
	visit_nodes(ref2);
	remove_head(ref2);
	visit_nodes(ref2);
	insert_head(ref2, "Chiamaka");
	visit_nodes(ref2);
	remove_tail(ref2);
	visit_nodes(ref2);
	delete_list(ref2);

	// int check = visit_nodes(ref);
	// if(LE_ISERROR(check))
	// 	printf("%s\n", le_errbuf);
	return 0;
}
Ejemplo n.º 4
0
int main()
{
	list l;
	init(&l);

	printf("Inserting 3, 4, 1, 5, 6 and 2 at the back of the list.\n");
	insert_back(&l, 3);
	insert_back(&l, 4);
	insert_back(&l, 1);
	insert_back(&l, 5);
	insert_back(&l, 6);
	insert_back(&l, 2);
	for_each_forward(&l, print_node, NULL);

	printf("Print list backwards.\n");
	for_each_backward(&l, print_node, NULL);

	printf("Inserting 5 in front of the list.\n");
	insert_front(&l, 5);
	for_each_forward(&l, print_node, NULL);

	printf("Removing tail.\n");
	remove_tail(&l);
	for_each_forward(&l, print_node, NULL);

	printf("Removing head.\n");
	remove_head(&l);
	for_each_forward(&l, print_node, NULL);

	printf("Add 5 to each element in the list.\n");
	int add=5;
	for_each_forward(&l, add_node, &add);
	for_each_forward(&l, print_node, NULL);

	printf("Freeing list.\n");
	for_each_forward(&l, free_node, NULL);
	return 0;
}
Ejemplo n.º 5
0
void SR_extractRef(SR_RefList **objectRefListpp, int delay, double *aDelayp, double *uDelayp, double *xDelayp)
{
  int i = 0;
  SR_RefList *sought;
 
  sought = *objectRefListpp;
  if (sought == NULL) //This should not happen..
    return;

  /* Find delayed references */
  while ((sought->older != NULL) && (i++ < delay))
    sought = sought->older;   

  /* Extract delayed references */
  *aDelayp = sought->a;
  *uDelayp = sought->u;
  *xDelayp = sought->x;

  if ((i > delay) && (sought->older != NULL)) { // Remove tail of post-delay references if it exists
    remove_tail(sought->older);
    sought->older = NULL;
  }
}
Ejemplo n.º 6
0
int		remove_node(t_ctrl **ctrl, const int nbr)
{
  t_list	*list;
  int		i;

  i = 0;
  list = (*ctrl)->head;
  if ((*ctrl)->size == 1)
    return (FAILURE);
  while (i < (*ctrl)->size && list->nbr != nbr)
    {
      list = list->next;
      i++;
    }
  if (list == NULL)
    return (FAILURE);
  else if (list == (*ctrl)->head)
    remove_head(ctrl, list);
  else if (list == (*ctrl)->tail)
    remove_tail(ctrl, list);
  else
    remove_else(ctrl, list);
  return (SUCCESS);
}
Ejemplo n.º 7
0
void snake::move(){
	add_head(remove_tail());
	object* h=body[(head+2)%maximum];
	int nx=h->getx()+dx;
	int ny=h->gety()+dy;
	int nz=h->getz();
	int side=0;
	if(nx<0){
		side=3;
		switch(_map->get_s_r(nz,side)){
			case 0:
				set_direction(0,1);
				nx=ny;
				ny=0;
			break;
			case 1:
				set_direction(-1,0);
				ny=ny;
				nx=M_SIZE-1;
			break;
			case 2:
				set_direction(0,-1);
				nx=M_SIZE-1-ny;
				ny=M_SIZE-1;
			break;
			case 3:
				set_direction(1,0);
				ny=M_SIZE-1-ny;
				nx=0;
			break;
		}
		nz=_map->get_f_r(nz,side);
		_map->rotate(side);
	}else if(ny<0){
		side=0;
		switch(_map->get_s_r(nz,side)){
			case 0:
				set_direction(0,1);
				nx=M_SIZE-1-nx;
				ny=0;
			break;
			case 1:
				set_direction(-1,0);
				ny=M_SIZE-1-nx;
				nx=M_SIZE-1;
			break;
			case 2:
				ny=M_SIZE-1;
			break;
			case 3:
				set_direction(1,0);
				ny=nx;
				nx=0;
			break;
		}
		nz=_map->get_f_r(nz,side);
		_map->rotate(side);
	}else if(nx==M_SIZE){
		side=1;
		switch(_map->get_s_r(nz,side)){
			case 0:
				set_direction(0,1);
				nx=M_SIZE-1-ny;
				ny=0;
			break;
			case 1:
				set_direction(-1,0);
				ny=M_SIZE-1-ny;
				nx=M_SIZE-1;
			break;
			case 2:
				set_direction(0,-1);
				nx=ny;
				ny=M_SIZE-1;
			break;
			case 3:
				set_direction(1,0);
				ny=ny;
				nx=0;
			break;
		}
		nz=_map->get_f_r(nz,side);
		_map->rotate(side);
	}else if(ny==M_SIZE){
		side=2;
		switch(_map->get_s_r(nz,side)){
			case 0:
				set_direction(0,1);
				nx=nx;
				ny=0;
			break;
			case 1:
				set_direction(-1,0);
				ny=nx;
				nx=M_SIZE-1;
			break;
			case 2:
				set_direction(0,-1);
				nx=M_SIZE-1-nx;
				ny=M_SIZE-1;
			break;
			case 3:
				set_direction(1,0);
				ny=M_SIZE-1-nx;
				nx=0;
			break;
		}
		nz=_map->get_f_r(nz,side);
		_map->rotate(side);
	}else{
	}
	body[head==maximum-1?0:(head+1)]->setpos(nx,ny,nz);
}