Advertisement
Nacho182

retorno metodos de clase

Dec 16th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*---------------------------------------------------------*/
  6.  
  7. template <class Elemento>
  8. class Lista
  9. {
  10.     private:
  11.             struct nodoLista
  12.             {
  13.                 Elemento valor;
  14.                 nodoLista * sig;
  15.             };
  16.  
  17.             nodoLista * lista;
  18.     public:
  19.             Lista ();
  20.             ~Lista();
  21.             void inserta_al_principio(Elemento valor);
  22.             void inserta_al_final(Elemento valor);
  23.             nodoLista * devuelve_nodo(int valor);
  24. };
  25.  
  26. /*---------------------------------------------------------*/
  27.  
  28.  
  29. template <class Elemento>
  30. nodoLista * lista<Elemento>::devuelve_nodo(int posicion)
  31. {
  32.     nodoLista * it = lista;
  33.     int cont = 1;
  34.  
  35.     while (it != 0)
  36.     {
  37.         if (cont == posicion)
  38.             return it;
  39.         it = it->sig;
  40.         cont++;
  41.     }
  42. }
  43.  
  44. /*---------------------------------------------------------*/
  45.  
  46. int main()
  47. {
  48.     Lista<int> lista;
  49.     ...
  50.     ...
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement