#include <conio.h>
#include <stdlib.h>
int cont;
struct slista
{
int elemento;
struct slista *anterior;
struct slista *siguiente;
};
class clista
{
private:
int elemento;
struct slista *ele_act;
public:
clista ();
~clista ();
void mover_siguiente ();
void mover_anterior ();
void mover_inicio ();
void mover_final ();
void mostrar_elemento ();
void insertar_elemento (int);
void lista_vacia ();
void borrar_elemento ();
void mostrar_listaasc ();
void mostrar_listades ();
};
clista::clista ()
{
elemento=0;
ele_act=NULL;
}
clista::~clista ()
{
if (ele_act!=NULL)
free (ele_act);
}
void clista::mover_siguiente ()
{
if (ele_act!=NULL)
{
clrscr ();
if (ele_act->siguiente!=NULL)
{
ele_act=ele_act->siguiente;
cout<<"\n\t\t******* Mover al siguiente *******"<<endl;
cout<<"\n\tElemento actual: "<<ele_act->elemento<<endl;
}
else
{
cout<<"\n\t\t******* Mover al siguiente *******"<<endl;
cout<<"\n\tNo hay siguiente...."<<endl;
}
}
getch ();
return;
}
void clista::mover_anterior ()
{
if (ele_act!=NULL)
{
clrscr ();
if (ele_act->anterior!=NULL)
{
ele_act=ele_act->anterior;
cout<<"\n\t\t******* Mover al anterior *******"<<endl;
cout<<"\n\tElemento actual: "<<ele_act->elemento<<endl;
}
else
{
cout<<"\n\t\t******* Mover al anterior *******"<<endl;
cout<<"\n\tNo hay elemento anterior...."<<endl;
}
}
getch ();
return;
}
void clista::mover_inicio ()
{
if (ele_act!=NULL)
{
while (ele_act->anterior!=NULL)
ele_act=ele_act->anterior;
clrscr ();
cout<<"\n\t\t******* Mover al inicio *******"<<endl;
cout<<"\n\tElemento actual: "<<ele_act->elemento<<endl;
}
getch ();
return;
}
void clista::mover_final ()
{
if (ele_act!=NULL)
{
while (ele_act->siguiente!=NULL)
ele_act=ele_act->siguiente;
clrscr ();
cout<<"\n\t\t******* Mover al final *******"<<endl;
cout<<"\n\tElemento actual: "<<ele_act->elemento<<endl;
}
getch ();
return;
}
void clista::mostrar_elemento ()
{
if (ele_act!=NULL)
{
clrscr ();
cout<<"\n\t\t******* Mostrar Elemento *******"<<endl;
cout<<"\n\tElemento Actual: "<<ele_act->elemento<<endl;
}
getch ();
return;
}
void clista::lista_vacia ()
{
clrscr ();
cout<<"\n\t\t******* Checar lista *******"<<endl;
if (ele_act==NULL)
cout<<"\n\tL I S T A V A C I A......"<<endl;
else
cout<<"\n\tL I S T A C O N "<<cont<<" E L E M E N T O S......"<<endl;
getch ();
return;
}
void clista::insertar_elemento (int ele)
{
struct slista *nuevo,*ant,*sig;
nuevo=(struct slista *)malloc (sizeof (struct slista));
nuevo->siguiente=nuevo->anterior=NULL;
nuevo->elemento=ele;
if (ele_act==NULL)
ele_act=nuevo;
else
{
while (ele_act->elemento>nuevo->elemento)
{
sig=ele_act;
ele_act=ele_act->anterior;
ant=ele_act;
if (ele_act==NULL)
break;
}
while (nuevo->elemento>ele_act->elemento)
{
ant=ele_act;
ele_act=ele_act->siguiente;
sig=ele_act;
if (ele_act==NULL)
break;
}
if (ant!=NULL)
ant->siguiente=nuevo;
nuevo->anterior=ant;
if (sig!=NULL)
sig->anterior=nuevo;
nuevo->siguiente=sig;
ele_act=nuevo;
}
cont++;
return;
}
void clista::borrar_elemento ()
{
struct slista *aux1,*aux2;
if (ele_act!=NULL)
{
if (ele_act->anterior==NULL && ele_act->siguiente==NULL)
ele_act=NULL;
else
{
if (ele_act->anterior==NULL)
{
aux1=ele_act;
ele_act=ele_act->siguiente;
ele_act->anterior=NULL;
free (aux1);
}
else
{
if (ele_act->siguiente==NULL)
{
aux1=ele_act;
ele_act=ele_act->anterior;
ele_act->siguiente=NULL;
free (aux1);
}
else
{
aux1=ele_act;
ele_act=aux1->anterior;
aux2=aux1->siguiente;
ele_act->siguiente=aux2;
aux2->anterior=ele_act;
free (aux1);
}
}
}
}
cont--;
getch ();
return;
}
void clista::mostrar_listaasc ()
{
if (ele_act!=NULL)
{
clrscr ();
struct slista *aux;
cout<<"\n\t\t******* Mostrar lista de manera ascendente *******"<<endl;
aux=ele_act;
cout<<"\n\tLista:"<<endl;
while (aux->anterior!=NULL)
aux=aux->anterior;
while (aux->siguiente!=NULL)
{
cout<<"\n\t\t\t"<<aux->elemento<<endl;
aux=aux->siguiente;
}
cout<<"\n\t\t\t"<<aux->elemento<<endl;
}
else
{
clrscr ();
cout<<"\n\t\t******* Mostrar lista de manera descendente *******"<<endl;
cout<<"\n\tNo hay elemento que mostrar....."<<endl;
}
getch ();
return;
}
void clista::mostrar_listades ()
{
if (ele_act!=NULL)
{
clrscr ();
struct slista *aux;
cout<<"\n\t\t******* Mostrar lista de manera descendente *******"<<endl;
aux=ele_act;
cout<<"\n\tLista:"<<endl;
while (aux->siguiente!=NULL)
aux=aux->siguiente;
while (aux->anterior!=NULL)
{
cout<<"\n\t\t\t"<<aux->elemento<<endl;
aux=aux->anterior;
}
cout<<"\n\t\t\t"<<aux->elemento<<endl;
}
else
{
clrscr ();
cout<<"\n\t\t******* Mostrar lista de manera descendente *******"<<endl;
cout<<"\n\tNo hay elemento que mostrar....."<<endl;
}
getch ();
return;
}
void main ()
{
clista l;
char sino;
int opc,ele;
do
{
clrscr ();
cout<<"\n\t\t******* Lista Doble *******"<<endl;
cout<<"\n\tMENU"<<endl;
cout<<"\n\t1.-Insertar"<<endl;
cout<<"\t2.-Checar lista"<<endl;
cout<<"\t3.-Borrar elemento"<<endl;
cout<<"\t4.-Ver elemento actual"<<endl;
cout<<"\t5.-Mover al anterior"<<endl;
cout<<"\t6.-Mover al siguiente"<<endl;
cout<<"\t7.-Ir al Inicio"<<endl;
cout<<"\t8.-Ir al Final"<<endl;
cout<<"\t9.-Imprimir lista (ascendente)"<<endl;
cout<<"\t10.-Imprimir lista (descendente)"<<endl;
cout<<"\t11.-Salir"<<endl;
cout<<"\n\tQue opcion desea realizar? [ ]";gotoxy(37,18);cin>>opc;
switch (opc)
{
case 1:
{
clrscr ();
cout<<"\n\t\t******* Insertar Elemento *******"<<endl;
cout<<"\n\tTeclee el elemento a insertar: ";cin>>ele;
l.insertar_elemento (ele);
sino='s';
break;
}
case 2:
{
l.lista_vacia ();
sino='s';
break;
}
case 3:
{
l.borrar_elemento ();
sino='s';
break;
}
case 4:
{
l.mostrar_elemento ();
sino='s';
break;
}
case 5:
{
l.mover_anterior ();
sino='s';
break;
}
case 6:
{
l.mover_siguiente ();
sino='s';
break;
}
case 7:
{
l.mover_inicio ();
sino='s';
break;
}
case 8:
{
l.mover_final ();
sino='s';
break;
}
case 9:
{
l.mostrar_listaasc ();
sino='s';
break;
}
case 10:
{
l.mostrar_listades ();
sino='s';
break;
}
case 11:
{
sino='n';
break;
}
}
}while (sino=='s' || sino=='S');
getch ();
}
ESE ES EL PROGRAMA...CHECALO EN C++ Y VERAS KE MARCA ERRORES.. ESPERO KE ME PUEDAS AYUDAR





