Error in option display list C ++ (simple linked list)

0

Hello, the following was good to see if someone could help me with this problem in my c ++ code, the option to insert data into the list works correctly but for some reason I can not show that data when executing the option 2:

void menu(){
    int opcion,dato;
    do{
        cout<<"\t.:MENU:.\n";
        cout<<"1. Insertar elementos a la lista\n";
        cout<<"2. Mostrar elementos de la lista\n";
        cout<<"3. Salir\n";
        cout<<"Opcion:  ";
        cin>>opcion;

        switch(opcion){
            case 1:
                    cout<<"\nDigite un numero:  ";
                    cin>>dato;
                    insertarLista(lista,dato);
                    cout<<"\n";
                    system("pause");
                    break;
            case 2: 
                mostrarLista(lista);
                cout<<"\n";
                system("pause");
                break;
        }
        system("cls");
    }while(opcion!= 3);
}
void insertarLista(Nodo *&lista,int n){
    //Pasos para insertar elementos a la lista
    //Crear nuevo nodo
    Nodo *nuevo_nodo = new Nodo();
    nuevo_nodo->dato= n;

    Nodo *aux1 = lista;
    Nodo *aux2;//CREACION DE DOS PUNTEROS

    while((aux1 != NULL) && (aux1->dato < n)){
        aux2=aux1;
        aux1=aux1->siguiente;
    }//BUCLE WHILE PARA MANTENER EL ORDEN DE LA  LISTA

    if(lista==aux1){
        lista == nuevo_nodo;//ESTO SE CUMPLE SIEMPRE Y CUANDO EL ELEMENTO VAYA AL PRINCIPIO DE LA LISTA

    }else{//DE LO CONTRARIO SI EL ELSE SE CUMPLE SIGNIFICA Q YA ENTRO AL WHILE Y YA HA CORRIDO UNA POSICION MAS
        aux2->siguiente=nuevo_nodo;
    }

    nuevo_nodo->siguiente = aux1;

    cout<<"\tElemento  "<<n<<" insertado a lista correctamente\n";

}
void mostrarLista(Nodo *lista){
    //crear nuevo nodo
    Nodo *actual= new Nodo();
    actual = lista;

    while(actual != NULL){// PARA RECORRER LA LISTA LEER LOS ELEMENTOS QUE NO SEAN NULLs
        cout<<actual->dato<<" -> ";
        actual=actual->siguiente;
    }

}
    
asked by Agustin Lyon 31.10.2018 в 23:26
source

0 answers