-
Notifications
You must be signed in to change notification settings - Fork 1
/
lista.h
105 lines (78 loc) · 2.82 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************
* Implementação simples de lista encadeada.
*
* Algoritmos em Grafos e Otimização
* Departamento de Informática - UFPR
* prof. Guilherme Derenievicz
*******************************************/
#ifndef _LISTA_
#define _LISTA_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _ERRO_MALLOC_ 1
// macros para cast de ponteiro de funcao:
#define void_f_obj void(*)(obj)
#define int_f_obj int(*)(obj)
#define str_f_obj char*(*)(obj)
typedef void *obj;
typedef struct t_no *no;
typedef struct t_lista *lista;
typedef struct t_no {
no proximo;
no anterior;
obj conteudo;
} t_no;
typedef struct t_lista {
no primeiro_no;
no ultimo_no;
} t_lista;
//---------------------------------------------------------
// getters:
no proximo(no n);
no anterior(no n);
obj conteudo(no n);
no primeiro_no(lista l);
no ultimo_no(lista l);
//---------------------------------------------------------
// funcoes da lista:
// cria lista vazia e a retorna
lista cria_lista();
// devolve 1 se a lista estiver vazia e 0 c.c.
int vazio(lista l);
// devolve o conteudo do inicio da lista e o mantem na lista
obj topo(lista l);
// devolve o conteudo do inicio da lista e o remove da lista
obj desempilha(lista l);
// insere o objeto no inicio da lista
void empilha(obj c, lista l);
// devolve o conteudo do final da lista e o mantem na lista
obj final(lista l);
// devolve o conteudo do final da lista e o remove da lista
obj remove_ultimo(lista l);
// insere o objeto no final da lista
void enfila(obj c, lista l);
// função auxiliar para remover um nó da lista
void remove_no(no n, lista l);
// devolve o conteudo com a chave <chave> e o mantem na lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj busca_chave_int(int chave, lista l, int f_chave(obj c));
// devolve o conteudo com a chave <chave> e o remove da lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj remove_chave_int(int chave, lista l, int f_chave(obj c));
// devolve o conteudo com a chave <chave> e o mantem na lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj busca_chave_str(char *chave, lista l, char *f_chave(obj c));
// devolve o conteudo com a chave <chave> e o remove da lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj remove_chave_str(char *chave, lista l, char *f_chave(obj c));
// devolve o conteudo com a menor chave e o mantem na lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj busca_min(lista l, int f_chave(obj c));
// devolve o conteudo com a menor chave e o remove da lista
// [a funcao <f_chave(c)> deve devolver a chave do objeto c]
obj remove_min(lista l, int f_chave(obj c));
// imprime a lista
// [a funcao <imprime(c)> deve imprimir o objeto c]
void imprime_lista(lista l, void imprime_conteudo(obj c));
#endif