This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lista.h
64 lines (48 loc) · 1.84 KB
/
lista.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
============================================================================
TRABALHO PRÁTICO 6 - Paralelismo
Algoritmos e Estruturas de Dados III
Bruno Maciel Peres
brunomperes@dcc.ufmg.br
LISTA.H - Define as estruturas de dados e cabeçalhos das funções relacionadas às operações sobre o TAD lista
============================================================================
*/
#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED
//Guarda o conteúdo relativo ao nó (preferência da pessoa)
typedef struct ITEM {
int indice; //Indica se é o 1º elemento, 2º elemento. É utilizado para buscas e calcular o índice de satisfabilidade
int valor; //Armazena a id do pretendente
} ITEM;
//Armazena os ponteiros para o próximo e para o nó anterior, além de uma estrutura contendo valores relativos à preferência da pessoa
typedef struct NO {
ITEM item;
struct NO *proximo;
struct NO *anterior;
} NO;
//Define a lista, que representará uma pessoa
typedef struct LISTA {
int casado;
int casado_com_id; //id do pretendente com o qual o interessado casou-se
NO *inicio;
NO *fim;
} LISTA;
//Cria uma lista vazia em O(1)
void lista_criar(LISTA *lista);
//Verifica se uma lista está vazia em O(1)
int lista_vazia(LISTA *lista);
//Apaga uma lista em O(n)
void lista_apagar(LISTA *lista);
//Push_front, O(1). Retorna 0 em caso de erro
int lista_inserir_inicio(LISTA *lista, ITEM *item);
//Remove um nó de uma lista em O(1)
void lista_remover_no(LISTA* lista, NO* no);
//Remove o primeiro elemento de uma lista em O(1)
void lista_remover_inicio(LISTA* lista);
//Push_back, O(1). Retorna 0 em caso de erro
int lista_inserir_fim(LISTA *lista, ITEM *item);
//Busca um valor contido em um nó em O(n)
NO* lista_busca(LISTA* lista, int valor);
//Imprime os valores de nó de uma lista encadeada
void lista_imprimir(LISTA *lista);
#endif // LIST_H_INCLUDED