Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T>
- bool Lista<T>::agregarElementoPosicion(T elem, int pos){
- if(not posicionValida(pos)){
- return false;
- }else {
- if (pos==1){
- this->agregarPrincipio(elem);
- return true;
- }else{
- nodoLista *cursor=primero;
- int posActual=1;
- while (posActual<pos-1){
- cursor=cursor->sig;
- posActual++;
- }
- nodoLista *temporal=new nodoLista;
- temporal->elem=elem;
- temporal->sig=cursor->sig;
- cursor->sig=temporal;
- longitud++;
- if(temporal->sig==0){ //actualiza el ultimo
- ultimo=cursor->sig;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement