Lista Encadeada
Started By xaves, 25/11/2004, 19:47
1 reply to this topic
#1
Posted 25/11/2004, 19:47
Olá, to encomodando de novo, mas estou com problemas para criar uma lista encadeada no C, e dinâmica, se alguém tiver algum tutorial ou um exemplo pra mim me ligar como é.....
• Xaves Corel | Pré-impressão | Photoshop | Programação
#2
Posted 02/12/2004, 11:42
isso eh um sacowww !!! droga pq nos temos que aprender essas coisas vio !
mas ai vai !
mas ai vai !
#include <stdlib.h>
#define OK 1
#define ERRO 0
#define TRUE 1
#define FALSE 0
struct reglista{
int info;
struct reglista *prox;
};
typedef struct reglista *lista;
//Inicializar fila :
int criar (lista *l){
*l = NULL;
return OK;
}
//Verificar se a fila esta vazia :
int vazia(lista l){
if(l == NULL){
return TRUE;
}
else{
return FALSE;
}
}
// Retona ao tamamho da fila
int tamanho(lista l){
int cont = 0;
while(l != NULL){
cont++;
l = l->prox;
}
return cont;
}
// Retornar a um elemento de determinada posicao :
lista elementopos(lista l, int posicao){
int i;
if(tamanho(l) >= posicao && posicao > 0){
for(i=1; i<posicao; i++){
l = l->prox;
}
return(l);
}
else{
return(NULL);
}
}
// Inserir dados na lista em ordem de chegada :
int inserir (lista *l, int valor){
lista nl;
nl = (lista) malloc(sizeof(lista));
nl->info = valor;
*l = nl;
return OK;
}
// Inserir dados na lista em uma determinada posicao :
int inserirpos(lista *l, int valor, int posicao){
lista nl, ea;
if(posicao == 1){
nl = (lista) malloc(sizeof(lista));
nl->info = valor;
nl->prox = *l;
*l = nl;
return OK;
}
else{
ea = elementopos(*l, posicao-1);
if(ea != NULL){
nl = (lista) malloc(sizeof(lista));
nl->info = valor;
nl->prox = ea->prox;
ea->prox = nl;
return OK;
}
else{
return ERRO;
}
}
}
Deveriam liberar imagens em php.
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)










