#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define p printf
struct nodo{
struct nodo *sig;
struct nodo *ant;
int dato;
};
struct nodo *cab1, *cab2;
int lista_vacia(struct nodo *);
int getnumero_nodos(struct nodo *);
struct nodo *crear_nodo();
void insertar(struct nodo *, int);
void eliminar(struct nodo *, int);
void main()
{
clrscr();
p("hola mundo");
insertar(cab1, 5);
insertar(cab1, 45);
//p(" * ***%d", cab1->dato);
getch();
}
int lista_vacia(struct nodo *cab)
{
return (cab==NULL);
}
int getnumero_nodos(struct nodo *cab)
{
struct nodo *aux;
int cont=0;
if(lista_vacia(cab)==1)
return 0;
else
{
for(aux=cab; aux!=NULL; aux= aux->sig)
{cont++;}
return (cont);
}
}
struct nodo *crear_nodo()
{
struct nodo *n;
n=(struct nodo *)malloc(sizeof(struct nodo));
if(n==NULL)
{
p("memoria llena..!!");
}
return n;
}
void insertar(struct nodo *c, int dato)
{
struct nodo *n, *aux;
n=crear_nodo();
if(n!=NULL)
{
n->dato=dato;
if(c==NULL)
{
c=n;
}
else
{
for(aux=c; aux->sig!=c; aux=aux->sig){}
aux->sig=n;
n->ant=aux;
n->sig=c;
c->ant=n;
}
}
p(" **%d", cab1->dato);
}
void eliminar(struct nodo *c, int dato)
{
struct nodo *aux;
for(aux=c; aux->dato!=dato; aux=aux->sig){}
if(aux==c)
{
c=c->sig;
aux->ant=c;
c->ant=aux->ant;
insertar(cab2, aux->dato);
free(aux);
}
else
{
aux->ant->sig=aux->sig;
aux->sig->ant=aux->ant;
insertar(cab2, aux->dato);
free(aux);
}
}
ayudenme con la solucion al intentar modificar la lista enviada por parametros..!! q no sale..
#include<conio.h>
#include<stdlib.h>
#define p printf
struct nodo{
struct nodo *sig;
struct nodo *ant;
int dato;
};
struct nodo *cab1, *cab2;
int lista_vacia(struct nodo *);
int getnumero_nodos(struct nodo *);
struct nodo *crear_nodo();
void insertar(struct nodo *, int);
void eliminar(struct nodo *, int);
void main()
{
clrscr();
p("hola mundo");
insertar(cab1, 5);
insertar(cab1, 45);
//p(" * ***%d", cab1->dato);
getch();
}
int lista_vacia(struct nodo *cab)
{
return (cab==NULL);
}
int getnumero_nodos(struct nodo *cab)
{
struct nodo *aux;
int cont=0;
if(lista_vacia(cab)==1)
return 0;
else
{
for(aux=cab; aux!=NULL; aux= aux->sig)
{cont++;}
return (cont);
}
}
struct nodo *crear_nodo()
{
struct nodo *n;
n=(struct nodo *)malloc(sizeof(struct nodo));
if(n==NULL)
{
p("memoria llena..!!");
}
return n;
}
void insertar(struct nodo *c, int dato)
{
struct nodo *n, *aux;
n=crear_nodo();
if(n!=NULL)
{
n->dato=dato;
if(c==NULL)
{
c=n;
}
else
{
for(aux=c; aux->sig!=c; aux=aux->sig){}
aux->sig=n;
n->ant=aux;
n->sig=c;
c->ant=n;
}
}
p(" **%d", cab1->dato);
}
void eliminar(struct nodo *c, int dato)
{
struct nodo *aux;
for(aux=c; aux->dato!=dato; aux=aux->sig){}
if(aux==c)
{
c=c->sig;
aux->ant=c;
c->ant=aux->ant;
insertar(cab2, aux->dato);
free(aux);
}
else
{
aux->ant->sig=aux->sig;
aux->sig->ant=aux->ant;
insertar(cab2, aux->dato);
free(aux);
}
}
ayudenme con la solucion al intentar modificar la lista enviada por parametros..!! q no sale..