예제 #1
0
		void agregar(Nodo *a, int pos) {
			if(first == NULL) {
				first = a;
				size++;
			}else if(pos == 1) {
				agregarInicio(a);
			}else if(pos > size) {
				agregarFinal(a);
			}else {
				Nodo *aux;
				aux = first;
				for(int i = 0; i < pos-2; i++) {
					aux = aux->getNext();
				}
				//Nodo* siguiente;
				//Nodo* anterior;
				//anterior = aux;
				//siguiente = aux->getNext();
				//a->setNext(siguiente);
				//anterior->setNext(a);
				a->setNext(aux->getNext());
				aux->setNext(a);
				size++;
			}
		}
예제 #2
0
		void agregarFinal(Nodo *a) {
			if(first == NULL) {		//La lista esta vacia
				first = a;
				size++;
			}else {
				Nodo *aux;
				aux = first;
				while(aux->getNext() != NULL) { // Mientras haya un nodo despues
					aux = aux->getNext();
				}
				aux->setNext(a);
				size++;
			}
		}