Advertisement
Guest User

Untitled

a guest
May 26th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. template<class T>
  2. bool Lista<T>::agregarElementoPosicion(T elem, int pos){
  3.     if(not posicionValida(pos)){
  4.         return false;
  5.     }else {
  6.         if (pos==1){
  7.             this->agregarPrincipio(elem);
  8.             return true;
  9.         }else{
  10.                 nodoLista *cursor=primero;
  11.                 int posActual=1;
  12.                 while (posActual<pos-1){
  13.                     cursor=cursor->sig;
  14.                     posActual++;
  15.                 }
  16.                 nodoLista *temporal=new nodoLista;
  17.                 temporal->elem=elem;
  18.                 temporal->sig=cursor->sig;
  19.                 cursor->sig=temporal;
  20.                 longitud++;
  21.                 if(temporal->sig==0){ //actualiza el ultimo
  22.                     ultimo=cursor->sig;
  23.                 }
  24.                 return true;
  25.             }
  26.         }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement