elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda! Listas Doblemente Enlazadas
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda! Listas Doblemente Enlazadas  (Leído 1,593 veces)
mordeki_99

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Ayuda! Listas Doblemente Enlazadas
« en: 30 Noviembre 2015, 00:45 am »

Hola Amigos!!!
Bueno me inscribí en este mi primer foro y quería si por favor me ayudaran a ver donde está mi error ya que en verdad no se el porque.
es sobre una Librería pero el método anterior & método siguiente que son la esencia por así decirlo de una Lista Dinámica Doble.
Bueno aquí les dejo todo el código Amigos:
LISTA .H
Código
  1. #define LISTA_H
  2. #include "libro.h"
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class nodo
  10. {
  11.    private:
  12.        libro data;
  13.        nodo *sig;
  14.        nodo *ant;
  15.  
  16.    public:
  17.  
  18.        void setData(libro dato)
  19.        {
  20.            data=dato;
  21.        }
  22.        void setSig(nodo* sigue)
  23.        {
  24.            sig=sigue;
  25.        }
  26.        void setAnt(nodo* antes)
  27.        {
  28.            ant=antes;
  29.        }
  30.        libro getData()
  31.        {
  32.            return data;
  33.        }
  34.        nodo* getSig()
  35.        {
  36.            return sig;
  37.        }
  38.        nodo* getAnt()
  39.        {
  40.            return ant;
  41.        }
  42.  
  43.     friend class listaD;
  44. };
  45.  
  46. class listaD
  47. {
  48.    public:
  49.        listaD()
  50.        {
  51.            hd=NULL;
  52.            t=NULL;
  53.        }
  54.        nodo *hd,*t;
  55.        void inicializa();
  56.        bool vacia();
  57.        void insertarordenado(libro);
  58.        void mostrar();
  59.        void siguiente(string);
  60.        void anterior(string);
  61.        void eliminar(string);
  62.        void buscar(string);
  63.        void eliminartodo();
  64. };
  65.  
  66. #endif // LISTA_H]

.CPP DE LA LISTA
Código
  1. #include "lista.h"
  2. #include "libro.h"
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. void listaD::inicializa()
  8. {
  9.    hd=NULL;
  10.    t=NULL;
  11. }
  12.  
  13. bool listaD::vacia()
  14. {
  15.    if(hd==NULL&&t==NULL)
  16.    {
  17.        return true;
  18.    }
  19.    else
  20.    {
  21.        return false;
  22.    }
  23. }
  24.  
  25. void listaD::insertarordenado(libro elemento)
  26. {
  27.    nodo *aux=hd;
  28.    nodo *tmp=new nodo;
  29.    tmp->setData(elemento);
  30.    tmp->setSig(NULL);
  31.    tmp->setAnt(NULL);
  32.    //elemento.mostrar();
  33.    //system("pause");
  34.   // cout<<"LISTACANCIONES"<<aux->elemento;
  35.  
  36.    if(hd==NULL)
  37.    {
  38.        hd=t=tmp;
  39.    }
  40.    else
  41.    {
  42.      if(hd->getData().getnombre()>elemento.getnombre())
  43.      {
  44.          tmp->sig=hd;
  45.          hd->ant=tmp;
  46.          hd=tmp;
  47.      }
  48.  
  49.      else
  50.      {
  51.          while(aux->getSig()&&aux->getSig()->getData().getnombre()<elemento.getnombre())
  52.          {
  53.              aux=aux->getSig();
  54.          }
  55.          tmp->sig=aux->sig;
  56.          tmp->ant=aux;
  57.          aux->sig=tmp;
  58.          if(tmp->getSig()) tmp->sig->ant=tmp;
  59.      }
  60.    }
  61. }
  62.  
  63. void listaD::mostrar()
  64. {
  65.    nodo *aux=hd;
  66.    listaD ls;
  67.    if(vacia())
  68.    {
  69.        cout<< "\tLISTA VACIA"<<endl;
  70.        system("pause");
  71.    }
  72.    else
  73.    {
  74.        while(aux!=NULL)
  75.        {
  76.  
  77.            aux->data.mostrar();
  78.            aux=aux->getSig();
  79.        }
  80.    }
  81. }
  82.  
  83. void listaD::eliminar(string elemento)
  84. {
  85.    nodo *aux=hd;
  86.  
  87.    if(vacia())
  88.    {
  89.        cout<< "\tLISTA VACIA"<<endl;
  90.        system("pause");
  91.    }
  92.    else
  93.    {
  94.        while(aux!=NULL&&aux->getData().getnombre()!=elemento)
  95.        {
  96.            aux=aux->getSig();
  97.        }
  98.        if(aux==NULL)
  99.        {
  100.            cout<< "\tNO ENCONTRADO"<<endl;
  101.            system("pause");
  102.        }
  103.        else if(aux==t&&aux==hd)
  104.        {
  105.            delete(aux);
  106.            t=hd=NULL;
  107.        }
  108.        else if(aux==t)
  109.        {
  110.            t=t->getAnt();
  111.            delete(aux);
  112.            t->sig=NULL;
  113.        }
  114.        else if(aux==hd)
  115.        {
  116.            hd=hd->getSig();
  117.            delete(aux);
  118.            t->ant=NULL;
  119.        }
  120.        else if(hd!=NULL&&t!=NULL)
  121.        {
  122.            aux->ant->sig=aux->sig;
  123.            aux->sig->ant=aux->ant;
  124.            delete(aux);
  125.        }
  126.    }
  127. }
  128.  
  129. void listaD::buscar(string elemento)
  130. {
  131.    nodo *tmp=hd;
  132.    int i=1, band=0;
  133.  
  134.    while(tmp!=NULL)
  135.    {
  136.        if(tmp->getData().getnombre()==elemento)
  137.        {
  138.            cout<< "\tELEMENTO ENCONTRADO"<<endl;
  139.            cout<< "\tPOSICION: "<<i<<endl;
  140.            system("pause");
  141.            tmp->getData().mostrar();
  142.            band=1;
  143.            system("pause");
  144.        }
  145.        tmp=tmp->getSig();
  146.        i++;
  147.    }
  148.  
  149.    if(band==0)
  150.    {
  151.        cout<< "\tELEMENTO NO ENCONTRADO"<<endl;
  152.        system("pause");
  153.    }
  154. }
  155.  
  156. void listaD::eliminartodo()
  157. {
  158.    nodo *tmp=hd=t;
  159.    if(hd==NULL&&t==NULL)
  160.    {
  161.        cout<< "\tLISTA VACIA"<<endl;
  162.        system("pause");
  163.    }
  164.    else
  165.    {
  166.        while(hd!=NULL)
  167.        {
  168.            tmp=hd=t;
  169.            hd=hd->getSig();
  170.            t=t->getSig();
  171.            delete(tmp);
  172.        }
  173.    }
  174. }
  175.  
  176. void listaD::siguiente(string elemento)
  177. {
  178.    nodo *aux=hd;
  179.  
  180.    if(vacia())
  181.    {
  182.        cout<< "\tLISTA VACIA"<<endl;
  183.        system("pause");
  184.    }
  185.    else
  186.    {
  187.        while(aux!=NULL&&aux->getData().getnombre()!=elemento)
  188.        {
  189.            aux=aux->getSig();
  190.        }
  191.        if(aux==NULL)
  192.        {
  193.            cout<< "\tNO EXISTE"<<endl;
  194.            system("pause");
  195.        }
  196.        else if(aux==t)
  197.        {
  198.            cout<< "\tULTIMO ELEMENTO"<<endl;
  199.            system("pause");
  200.        }
  201.        else if(aux->getData().getnombre()==elemento)
  202.        {
  203.            cout<< "\tSIGUIENTE"<<endl;
  204.            aux->getSig()->getData().mostrar();
  205.        }
  206.    }
  207. }
  208.  
  209.  
  210. void listaD::anterior(string elemento)
  211. {
  212.    nodo *aux=t;
  213.  
  214.    if(vacia())
  215.    {
  216.        cout<< "\tLISTA VACIA"<<endl;
  217.        system("pause");
  218.    }
  219.    else
  220.    {
  221.        while(aux!=NULL&&aux->getData().getnombre()!=elemento)
  222.        {
  223.            aux=aux->getAnt();
  224.        }
  225.        if(aux==NULL)
  226.        {
  227.            cout<< "\tNO ENCONTRADO"<<endl;
  228.            system("pause");
  229.        }
  230.  
  231.        else if(aux==hd)
  232.        {
  233.            cout<< "\tPRIMER ELEMENTO"<<endl;
  234.            system("pause");
  235.        }
  236.  
  237.        else if(aux->getData().getnombre()==elemento)
  238.        {
  239.            cout<< "\tANTERIOR"<<endl;
  240.            aux->getAnt()->getData().mostrar();
  241.        }
  242.    }
  243. }

Espero Contar con su ayuda por favor la verdad no tengo idea por que no muestre. el método mostrar si funciona igual si quiere lo que viene siendo el .h y .cpp de el libro que es donde se ira guardando todo ala lista estaré al pendiente de sus respuestas.
Saludos!!!!!!!


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines