0
void List::remove_last()
{
	
	if(first == NULL)
	{
		first -> data = ' ';
	}
	else
	{
		
		Node *newnode;
		newnode = new Node;
		newnode = NULL;
		newnode -> data = last -> back -> data;
		last = newnode;
		
	}
}

am I doing something wrong? I'm trying to remove the end of list node.

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by sunn shine
0
newnode = new Node;
newnode = NULL;

Eerrrr? That's a bit of weird code. You're trying to derefence that pointer on the next line! ;)

0
newnode = new Node;
newnode = NULL;

Eerrrr? That's a bit of weird code. You're trying to derefence that pointer on the next line! ;)

void List::remove_last()
{
	
	if(first == NULL && last == NULL)
	{}
	else
	{
		
		Node *temp;
		temp = last -> back;
		delete last;
		last = temp;
		
	}
}

how about this code? either way it is not not running right.

0

nvm figured it out, i forgot to do temp->next = NULL; before i assigned it to last.

0

what is code of removing if we want user to enter value from the list to remove in doubly linked list?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.