void LinkedList::remove(int pos)//removes a picture at a position
{
	PictureNode *one_to_remove = new PictureNode;
	one_to_remove = walkToPosition(pos);
	if (one_to_remove->next != 0 && one_to_remove->prev != 0)
	{
		one_to_remove->prev->next = one_to_remove->next;
		one_to_remove->next->prev = one_to_remove->prev;
		one_to_remove->next = 0;
		one_to_remove->prev = 0;
		delete one_to_remove;
	}
	if (one_to_remove->next == 0 && one_to_remove->prev == 0)
	{
		delete one_to_remove;
	}
	if (one_to_remove->next != 0 && one_to_remove->prev == 0)
	{
		one_to_remove->next->prev = 0;
		delete one_to_remove;
	}
	if (one_to_remove->prev != 0 && one_to_remove->next == 0)
	{
		one_to_remove->prev->next = 0;
		delete one_to_remove;
	}
	else
	{
		
	}
	
}
void PictureLinkedList::insert(int pos, std::string value)
{
	// Let's assume we have 10 cars
	PictureNode *newNode = new PictureNode;
	newNode->picturePath = value;
	newNode->next = 0;
	// we need a pointer to car1 and car2
	PictureNode *pic_at_position = walkToPosition(pos);

	// now we can do the switching
	// The new car is attached to the next car after it
	if (pic_at_position == 0) {
		// This is the first car
		head = newNode;
		head->next = 0;
		head->prev = 0;
	}
	else {
		newNode->next = pic_at_position->next;
		newNode->prev = pic_at_position;

		if (newNode->next != 0) {
			newNode->next->prev = newNode;
		}
		pic_at_position->next = newNode;

	}
}
void LinkedList::insert(int pos, std::string path)//inserts a picture at a given location
{
	//create a new picture and give it some data
	PictureNode *insertedPicture = new PictureNode;
	insertedPicture->picturePath = path;
	//we need another pointer to the picture at the position before where we want to insert
	//so walk to that position and assign that position to a new pointer
	PictureNode *picture_at_pos = walkToPosition(pos);
	//now do the inserting
	if (picture_at_pos == 0) //if it's the very first node
	{
		head = insertedPicture;
		head->next = 0;
		head->prev = 0;
	}
	else
	{
		//assign the inserted picture's next to the previous picutures next (inserting into position)
		insertedPicture->next = picture_at_pos->next;
		//reassigns the previous pictures's next to the new picture
		picture_at_pos->next = insertedPicture;
		//reassigns the inserted picture to the previous picture
		insertedPicture->prev = picture_at_pos;
		//reassign the next picture's previous to the inserted picture
		if (insertedPicture->next != 0)
		{
			insertedPicture->next->prev = insertedPicture;

		}
		
	}
	
	
}
void PictureList::remove(int pos)// Removes element at given position
{
	
		PictureNode *tmp_node = walkToPosition(pos);
		if (tmp_node->next)
		{
			PictureNode *to_delete = tmp_node->next;
			tmp_node->next = to_delete->next;
			tmp_node->next->prev = tmp_node;
			delete to_delete;
		}
		else if (!tmp_node->next)
		{
			PictureNode *to_delete = tmp_node->prev;
			tmp_node->prev = to_delete->prev;
			tmp_node->prev->next = tmp_node;
			delete to_delete;
			
		}
		else {

		}
		
	

	
	
}
void PictureList::insert(int pos, std::string value)// Inserts the value at the given index
{
	PictureNode *newNode = new PictureNode;
	newNode->picturePath = value;
	newNode->next = 0;

	PictureNode *pic_at_position = walkToPosition(pos);

	if (pic_at_position == 0)
	{
		head = newNode;
		head->next = 0;
		head->prev = 0;
	}
	else
	{
		newNode->next = pic_at_position->next;
		newNode->prev = pic_at_position;

		if (newNode->next != 0)
		{
			newNode->next->prev = newNode;
		}
		pic_at_position->next = newNode;

	}

}
void PictureLinkedList::remove(int pos)
{
	PictureNode *tmp_node = walkToPosition(pos);
	PictureNode *to_delete = tmp_node->next;
	tmp_node->next = to_delete->next;
	tmp_node->next->prev = tmp_node;
	delete to_delete;
}
std::string PictureLinkedList::get(int pos)
{
	PictureNode *pic = walkToPosition(pos);
	return pic->picturePath;
}
void LinkedList::set(int pos, std::string value) //sets a new path to a picure at a certain position
{
	PictureNode *pic = walkToPosition(pos);
	pic->picturePath = value;
}
std::string  LinkedList::get(int pos)//returns the path of a picture at a position
{
	PictureNode *pic = new PictureNode;
	pic->picturePath = walkToPosition(pos)->picturePath;
	return pic->picturePath;
}
Exemple #10
0
std::string PictureList::get(int pos) //returns element at that position
{
	PictureNode *pic = walkToPosition(pos);
	return pic->picturePath;
}