Estrutura

531 palavras 3 páginas
/******************************************************************************
// listaLigadaD.c
// Este programa gerencia listas lineares ligadas (implementacao dinamica).
// As listas gerenciadas podem ter um numero arbitrario de elementos.
// Não usaremos sentinela nesta estrutura.
******************************************************************************/
#include
#define ERRO -1
#define true 1
#define false 0

typedef int bool; typedef int TIPOCHAVE;

typedef struct tempRegistro{ TIPOCHAVE chave; struct tempRegistro *prox;
// outros campos...
} REGISTRO;

typedef REGISTRO* PONT;

typedef struct { PONT inicio;
} LISTA;

/* Inicialização da lista ligada (a lista jah esta criada e eh apontada pelo endereco em l) */ void inicializarLista(LISTA *l){ l->inicio = NULL;
} /* inicializarLista */

/* Exibição da lista seqüencial */ void exibirLista(LISTA *l){ PONT end = l->inicio; printf("Lista: \" "); while (end != NULL){ printf("%d ", end->chave); // soh lembrando TIPOCHAVE = int end = end->prox; } printf("\"\n");
} /* exibirLista */

/* Retornar o tamanho da lista (numero de elementos) */ int tamanho(LISTA *l) { PONT end = l->inicio; int tam = 0; while (end != NULL){ tam++; end = end->prox; } return tam;
} /* tamanho */

/* Retornar o tamanho em bytes da lista. Neste caso, isto depende do numero de elementos que estao sendo usados. */ int tamanhoEmBytes(LISTA *l) { return(tamanho(l)*sizeof(REGISTRO))+sizeof(LISTA); // sizeof(LISTA) = sizeof(PONT) pois a "LISTA" eh um ponteiro para o 1o elemento
} /* tamanhoEmBytes */

/* Busca sequencial (lista ordenada ou nao) */
PONT buscaSeq(TIPOCHAVE ch, LISTA *l){ PONT pos = l->inicio; while (pos != NULL){ if (pos->chave == ch) return pos; pos = pos->prox; } return NULL;
} /* buscaSeq */

/* Busca sequencial - funcao de exclusao (retorna no endereço *ant o indice do elemento

Relacionados

  • estruturas
    663 palavras | 3 páginas
  • Estrutura
    1545 palavras | 7 páginas
  • Estruturas
    5123 palavras | 21 páginas
  • Estruturas
    1100 palavras | 5 páginas
  • Estruturas
    5130 palavras | 21 páginas
  • Estrutura
    2126 palavras | 9 páginas
  • Estruturas
    5393 palavras | 22 páginas
  • Estrutura
    1803 palavras | 8 páginas
  • estruturas
    1858 palavras | 8 páginas
  • Estruturas
    3693 palavras | 15 páginas