int main(void)
{
  List *list;

  list = NULL;
  if (add_node(&list, "Holberton") == 1)
    return (1);
  print_list(list);
  if (add_node(&list, "CA 94111") == 1)
    return (1);
  print_list(list);
  if (insert_in_list(&list, "98 Battery St.", 1) == 1)
    return (1);
  print_list(list);
  if (insert_in_list(&list, "School", 2) == 1)
    return (1);
  print_list(list);
  if (insert_in_list(&list, "School", 0) == 1)
    return (1);
  print_list(list);
  if (insert_in_list(&list, "School", 10) == 1)
    return (1);
  print_list(list);


  return (0);
}
/* insert_in_list_on_position inserts a new item on the indicated position of a list */
void insert_in_list_on_position(object_type item, list_pointer *p, list_type *list)
{
	list_pointer aux=*p;

	if (aux==NULL)
	{
		*p=NULL;
		return;
	}
	/* Tests if the pointer is pointing to the dummy cell.
	 * In this case we will just insert the item on the last of the list */
	if (aux==list->first)
	{
		insert_in_list(item, list);
	}
	else
	{
		/* Tests if the pointer is pointing to the real first item of the list.
		 * In this case we will insert the item on the first position of the list */
		
		if(aux==list->first->next)	
			insert_in_begin_list(item, list);
		else
		{
			aux->previous->next=alloc_cell();
			aux->previous->next->previous=aux->previous;
			aux->previous=aux->previous->next;
			aux->previous->item=item;
			aux->previous->next=aux;
			list->length++;
		}
	}
	*p=aux->previous;
}
Exemple #3
0
int		add_client(t_server *server, int fd)
{
  t_client	*client;
  t_sock	client_sin;
  socklen_t	client_sin_len;

  if ((client = (t_client *)my_malloc(sizeof(t_client), NEW_CLIENT)) == NULL)
    return (0);
  client_sin_len = (socklen_t)sizeof(client_sin);
  if ((client->cs = accept(fd, (struct sockaddr *)&client_sin,
			   &client_sin_len)) == -1)
    {
      perror("accept");
      return (-1);
    }
  client->fd_type = FD_CLI;
  client->client_function = read_for_client;
  client->my_team = NULL;
  client->my_cell = NULL;
  if (insert_in_list(&server->new_clients, client) == -1)
    return (-1);
  if (write(client->cs, "BIENVENUE\n", strlen("BIENVENUE\n")) == -1)
    {
      perror("write");
      return (-1);
    }
  return (0);
}
Exemple #4
0
static void
handle_biggest_offenders(int testtblsize, int maxcolors) {
    int i, j;
    float dEthresh = 0;
    CmapEntry *pCmap;

    num_offenders = 0;

    for (pCmap = virt_cmap, i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
	if (pCmap->nextidx < 0) {
	    continue;
	}
	if (num_offenders == MAX_OFFENDERS
	    && pCmap->dE < offenders[MAX_OFFENDERS-1]->dE)
	{
	    continue;
	}
	find_nearest(pCmap);
	insert_in_list(pCmap);
    }

    if (num_offenders > 0) {
	dEthresh = offenders[num_offenders-1]->dE;
    }

    for (i = 0; (total < maxcolors) && (i < num_offenders); ++i) {
	pCmap = offenders[i];

	if (!pCmap) continue;

	j = add_color(pCmap->red, pCmap->green, pCmap->blue, FALSE);

	if (j) {
	    for (j = i+1; j < num_offenders; ++j) {
		float dE;

		pCmap = offenders[j];
		if (!pCmap) {
		    continue;
		}

		find_nearest(pCmap);

		dE = pCmap->dE;
		if (dE < dEthresh) {
		    offenders[j] = 0;
		} else {
		    if (offenders[i+1] == 0 || dE > offenders[i+1]->dE) {
			offenders[j] = offenders[i+1];
			offenders[i+1] = pCmap;
		    }
		}
	    }
	}
    }
}
struct sll * convert_to_list(char a[])
{
	int i=0;
	struct sll *head=NULL;
	
	while(a[i]!='\0')
	{
		head=insert_in_list(a[i]-'0',head);
		i++;
	}
	return shuffle_odd_even(head,head);
}
struct sll * convert_to_list(char a[])
{
	int i=0;
	struct sll *head=NULL;
	
	while(a[i]!='\0')
	{
		head=insert_in_list(a[i]-'0',head);
		i++;
	}
	return head;
}
int main ()
{
    list l = create_list();
    prepend (&l, (void*)2);
    append (&l, (void*)17);
    insert_in_list (&l, 3, (void*)1);
    insert_in_list (&l, 2, (void*)14);
    display_list(l);
    printf ("\n");
    display_list_reverse(l);
    printf ("\n");
    delete_from_list (&l,2);
    display_list(l);
    printf ("\n");
    display_list_reverse(l);
    printf ("\n");
    set (l, 3, (void*)5);
    display_list(l);
    printf ("\n");
    display_list_reverse(l);
    return 0;
}
Exemple #8
0
int		add_stone(t_mineral type, t_server *server)
{
  u_int		x;
  u_int		y;
  t_mineral	*mineral;

  if ((mineral = (t_mineral *)my_malloc(sizeof(t_mineral), MIN)) == NULL)
    return (-1);
  x = rand() % server->width;
  y = rand() % server->height;
  *mineral = type;
  if (insert_in_list(&server->world[x][y].minerals, mineral) == -1)
    return (-1);
  return (0);
}
int receive_database(list_type *object_list, int number_of_dimensions, InputPortHandler input_port)
{
	int msg_size=2*sizeof(int)+number_of_dimensions*sizeof(float);	// size of the mesage that will be received 
	void *message;
	message=malloc(msg_size);	// message that will received

	object_type object;
	
	while (ahReadBuffer (input_port, message, msg_size) != EOW)
	{
		/* Get an object from the message */
		
		get_object_from_msg(&object, number_of_dimensions, message);
		insert_in_list(object, object_list);
	}

	free(message);
	return 1;
}