sistemas-operacionais/p00/queue.c
//------------------------------------------------------------------------------
// Remove o elemento indicado da fila, sem o destruir.
// Condicoes a verificar, gerando msgs de erro:
// - a fila deve existir
// - a fila nao deve estar vazia
// - o elemento deve existir
// - o elemento deve pertencer a fila indicada
// Retorno: 0 se sucesso, <0 se ocorreu algum erro
Remove o elemento indicado da fila, sem o destruir.
Condicoes a verificar, gerando msgs de erro:
a fila deve existir
a fila nao deve estar vazia
o elemento deve existir
o elemento deve pertencer a fila indicada
Retorno: 0 se sucesso, <0 se ocorreu algum erro
Remove o elemento indicado da fila sem o destruir . Condicoes a verificar gerando msgs de erro : a fila deve existir a fila nao deve estar vazia o elemento deve existir o elemento deve pertencer a fila indicada Retorno : 0 se sucesso <0 se ocorreu algum erro
int queue_remove (queue_t **queue, queue_t *elem){
	if ( !queue ){
		fprintf(stderr, "The queue doesn't exist\n");
		return -1;
	}
	if ( !(* queue) ){
		fprintf(stderr, "The queue is empty\n");
		return -5;
	}
	if ( !elem ){
		fprintf(stderr, "The element doesn't exist\n");
		return -2;
	}
	if ( elem->next == NULL || elem->prev == NULL ){
		fprintf(stderr, "The element is not in any queue \n");
		return -6;
	}
	if ( (* queue) != elem ){
		queue_t *aux = (* queue)->next;
		while ( aux != elem && aux != (* queue) )
			aux = aux->next;
		if ( aux == (* queue) ){
			fprintf(stderr, "The element is in other queue\n");
			return -3;
		}
	}
	else {
		if ( (* queue)->next == (* queue) && (* queue)->prev == (* queue) ){
			(* queue)->next = NULL;
			(* queue)->prev = NULL;
			(* queue)       = NULL;
			return 0;
		}
		else
			(* queue) = (* queue)->next;
	}
	elem->prev->next = elem->next;
	elem->next->prev = elem->prev;	
	elem->next = NULL;
	elem->prev = NULL;
	return 0;
}
int queue_remove ( queue_t * * queue , queue_t * elem ) { if ( ! queue ) { fprintf ( stderr , " \n " ) ; return -1 ; } if ( ! ( * queue ) ) { fprintf ( stderr , " \n " ) ; return -5 ; } if ( ! elem ) { fprintf ( stderr , " \n " ) ; return -2 ; } if ( elem -> next == NULL || elem -> prev == NULL ) { fprintf ( stderr , " \n " ) ; return -6 ; } if ( ( * queue ) != elem ) { queue_t * aux = ( * queue ) -> next ; while ( aux != elem && aux != ( * queue ) ) aux = aux -> next ; if ( aux == ( * queue ) ) { fprintf ( stderr , " \n " ) ; return -3 ; } } else { if ( ( * queue ) -> next == ( * queue ) && ( * queue ) -> prev == ( * queue ) ) { ( * queue ) -> next = NULL ; ( * queue ) -> prev = NULL ; ( * queue ) = NULL ; return 0 ; } else ( * queue ) = ( * queue ) -> next ; } elem -> prev -> next = elem -> next ; elem -> next -> prev = elem -> prev ; elem -> next = NULL ; elem -> prev = NULL ; return 0 ; }
Remove o elemento indicado da fila, sem o destruir.
Remove o elemento indicado da fila sem o destruir .
// check if the queue exists // check if the queue is empty // check if the element exists // check if the element is in any queue // check if the element is in the queue // if element is not the first element, check if is in the queue // else, element is the first element of the queue // check if the element is in other queue // check if there's only one element in the queue // if there's only one element in the queue, queue now is empty // else, the new queue first element is the second element