TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

A Estrutura de Deque em C

Por:   •  19/10/2020  •  Trabalho acadêmico  •  1.018 Palavras (5 Páginas)  •  138 Visualizações

Página 1 de 5

#include <stdio.h>

#include <malloc.h>

#include <stdbool.h>

typedef int TIPOCHAVE;

typedef struct{

int chave;

int valor;

}REGISTRO;

typedef struct tempRegistro{

REGISTRO reg;

struct tempRegistro * prox;

}ELEMENTO;

typedef ELEMENTO* PONT;

typedef struct{

PONT cabeca;

}LISTA;

void inicializarLista(LISTA * l){

l->cabeca = (PONT) malloc(sizeof(PONT));

l->cabeca->prox = l-> cabeca;

//No cabeça aponta para ele mesmo

printf("Lista inicializada");

}

int tamanhoLista(LISTA * l ){

PONT end = l->cabeca->prox;

int tam = 0;

while(end != l->cabeca){

end = end->prox;

}

return tam;

}

void exibirLista(LISTA * l){

PONT end = l->cabeca->prox;

printf("\n");

while(end != l->cabeca){

printf("( %i )->",end->reg.chave);

end = end->prox;

}

printf("\n");

}

PONT buscaSentinela(LISTA * l, TIPOCHAVE ch){

PONT pos = l->cabeca->prox;

while(pos->reg.chave != ch) pos = pos->prox;

if(pos != l->cabeca) return pos;

return NULL;

}

//Busca auxiliar

PONT buscaSeqExc(LISTA * l, TIPOCHAVE ch, PONT* ant){

*ant = l->cabeca;

PONT atual = l->cabeca->prox;

l->cabeca->reg.chave = ch;

while(atual->reg.chave< ch){

*ant = atual;

atual = atual->prox;

}

if(atual != l->cabeca && atual->reg.chave == ch) return atual;

return NULL;

}

//Inserindo elemento na lista

bool inserirElemLista(LISTA* l, REGISTRO reg){

PONT ant,i;

i= buscaSeqExc(l,reg.chave,&ant);

if(i != NULL) return false;

i = (PONT) malloc(sizeof(ELEMENTO));

i->reg = reg;

i->prox = ant->prox;

ant->prox = i;

return true;

}

//Excluindo elemento da lista

bool excluirElemLista(LISTA * l, TIPOCHAVE ch){

PONT ant,i;

i = buscaSeqExc(l,ch,&ant);

...

Baixar como (para membros premium)  txt (3.3 Kb)   pdf (38.8 Kb)   docx (9.7 Kb)  
Continuar por mais 4 páginas »
Disponível apenas no TrabalhosGratuitos.com