Código
#include <stdio.h>
#include <stdlib.h>
enum opcion {EXIT,INSERT,FIND,DELETE,SHOW,CURR,NEXT,PREV,FINDPREV,FINDNEXT};
struct nodo {
char nombre[40];
struct nodo *next;
struct nodo *prev;
};
int numNodos;
int pos;
struct nodo *head, *tail;
struct nodo *crearNodo () {
struct nodo *x;
x->next=NULL;
x->prev=NULL;
numNodos++;
return x;
}
struct nodo *buscar_ant (struct nodo *act) {
char *k= act->nombre;
if (act == NULL) return NULL;
act= act->prev;
while (act) {
break;
act= act->prev;
}
return act;
}
struct nodo *buscar_sig (struct nodo *act) {
char *k= act->nombre;
if (act == NULL) return NULL;
act= act->next;
while (act) {
break;
act= act->next;
}
return act;
}
struct nodo *buscar (struct nodo *lista, char *k) {
struct nodo *actual;
char aux [40];
int p = 1;
int encontrado = 0;
actual = lista;
while (p <= numNodos)
{
{
encontrado = 1;
}
p++;
actual = actual->next;
}
if (encontrado==0)
}
// operacion eliminar: elimina el primer nodo que coincida con la llave k
// recibe referencia del apuntador al inicio de la lista y llave a eliminar
// devuelve el nodo eliminado o null si no se encuentra el nodo
struct nodo *borrar (struct nodo *lista, char *k) {
struct nodo *aux;
struct nodo *actual;
int nodo_eliminar;
int x;
if(nodo_eliminar > numNodos || nodo_eliminar < 1)
if(nodo_eliminar == 1) {
aux = lista;
lista = lista->next;
if(lista == NULL)
tail = NULL;
else
lista->prev == tail;
}
else if(nodo_eliminar == numNodos)
{
aux = tail;
tail->prev->next = tail;
tail = tail->prev;
}else {
actual = tail;
for(x=1; x<nodo_eliminar;++x)
actual = actual->next;
aux = actual;
actual->prev->next = actual->next;
actual->next->prev = actual->prev;
}
numNodos--;
}
void listar (struct nodo *lista) {
struct nodo *actual;
pos=1;
actual=lista;
while(pos<=numNodos)
{
lista= lista->next;
pos++;
}
if(numNodos==0)
}
struct nodo *insertar (struct nodo *head, struct nodo *x) {
if (head != NULL) {
head->prev= x; // El antecesor al primer nodo de la lista apunta al nuevo nodo
x->next= head; // El sucesor del nuevo nodo apunta al primer nodo de la lista
}
head= x; // El inicio de la lista apunta al nuevo nodo
return head;
}
struct nodo *curr (struct nodo *actual) {
if (actual) {
return actual;
}
return actual;
}
struct nodo *prev (struct nodo *actual) {
if (actual && actual->prev) {
return actual->prev;
}
return actual;
}
struct nodo *next (struct nodo *actual) {
if (actual && actual->next) {
return actual->next;
}
return actual;
}
int main ()
{
char nombre[40];
enum opcion op= EXIT;
struct nodo *x,*act=NULL;
struct nodo *head= NULL;
struct nodo *tail= NULL;
struct nodo *lista;
char aux [40];
int p = 1;
int encontrado = 0;
while (1) {
switch (op) {
case INSERT:
x= insertar (head,crearNodo ());
if (head == NULL) // No hay nodos
tail= x;
head= x; // Head apunta al nuevo nodo
tail->next= head; // Siguiente del ultimo nodo apunta al primer nodo
head->prev= tail; // Anterior del primer nodo apunta al ultimo nodo
act= head; // Nodo actual apunta a primer nodo
break;
case FIND:
x= buscar (head,nombre);
break;
case DELETE:
x= borrar (head,nombre);
break;
case SHOW:
listar (head);
break;
case CURR:
curr (act);
break;
case NEXT:
act= next (act);
break;
case PREV:
act= prev (act);
break;
case FINDNEXT:
x= buscar_sig (act);
if (x != NULL) {
act= x;
}
else
break;
case FINDPREV:
x= buscar_ant (act);
if (x != NULL) {
act= x;
}
else
break;
case EXIT:
return;
default:
}
}
}
Alguna idea?





 Autor
 Autor
		

 En línea
									En línea
								
 
						