Esempio n. 1
0
template <class Type> bool MyList<Type>::push(Type _element, const int &_position){
	if(id == _position){

		MyList<Type> *newElement = new MyList(_element);
		newElement->setID(id);
		newElement->setNext(this);
		newElement->setPrevious(previous);
		
//		std::cout<<"created\n";

		if(previous!=NULL){
			previous->setNext(newElement);
		}


		setPrevious(newElement);

//		std::cout<<"links set\n";

		this->changeID(id + 1);

//		std::cout<<"id changed\n";

		return true;
	}
	else{
		if(next != NULL){
			return next->push(_element, _position);
		}
		else{
			return false;
		}
	}
}
Esempio n. 2
0
template <class Type> void MyList<Type>::pushBack(Type _element){
	size++;
	if(next==NULL){
		MyList<Type> *newElement = new MyList(_element);
		newElement->setID(id + 1);
		newElement->setPrevious(this);
		next = newElement;
	}
	else{
		next->pushBack(_element);
	}
}