martes, 6 de septiembre de 2016

Código

#include <iostream>
#include <stdlib.h>
using namespace std;

struct nodo{
       int numero;        // en este caso es un numero entero
       struct nodo *sgte;
};

typedef struct nodo *Tlista;

void insertarInicio(Tlista &lista, int valor)
{
    Tlista q;
    q = new(struct nodo);
    q->numero = valor;
    q->sgte = lista;
    lista  = q;
}
void reportarLista(Tlista lista)
{
     int i = 0;

     while(lista != NULL)
     {
          cout <<' '<< i+1 <<") " << lista->numero << endl;
          lista = lista->sgte;
          i++;
     }
}
void menu1()
{
    cout<<"\n\t\tLISTA ENLAZADA SIMPLE\n\n";
    cout<<" 1. INSERTAR AL INICIO               "<<endl;
    cout<<" 2. REPORTAR LISTA                   "<<endl;
    cout<<" 3. SALIR                            "<<endl;

    cout<<"\n INGRESE OPCION: ";
}

/*                        Funcion Principal
---------------------------------------------------------------------*/

int main()
{
    Tlista lista = NULL;
    int op;     // opcion del menu
    int _dato;  // elemenento a ingresar
    int pos;    // posicion a insertar


    system("color 0b");

    do
    {
        menu1();  cin>> op;

        switch(op)
        {
            case 1:

                 cout<< "\n NUMERO A INSERTAR: "; cin>> _dato;
                 insertarInicio(lista, _dato);
            break;

          case 2:
          cout << "\n\n MOSTRANDO LISTA\n\n";
                 reportarLista(lista);
            break;


                    }

        cout<<endl<<endl;
        system("pause");  system("cls");

    }while(op!=3);


   system("pause");
   return 0;
}

No hay comentarios:

Publicar un comentario