what the wrong for this code :

if (head==NULL)//1 if the list is embty 
cout<<"NO element in linked list ";
else if {
if (head==tail){ ///2- if we have one node 
delete head ;

how i can write the other case
if valid addrese
if the addrese in first node
if the addrese last node
if the addrese between two node .-> more than two node .node before ande node after that addrese ..


5 Years
Discussion Span
Last Post by programing

I'm not really understanding your question. But, going by your thread title, to delete a particular position, you would basically follow these steps.
1. Point iterator to the first position in list
2. Move the iterator forward until you reach your desired index(e.g. for loop)
3. Make the current nodes PREVIOUS node, point to the current nodes NEXT node.
4. Make the current nodes NEXT node, point to the current nodes PREVIOUS node.
5. Delete the current node.

<-(previous)->  <-(current)->  <-(next)->

<-(prevous)->  <-(next)->

<-(prevous)->  <-(next)->

Edited by Akill10: n/a


yes , what you understanded is true ..
. but , there is subcase ..
if the value is found maybe its in the head // i mean one node
or in the tail .
or between
position effect or not ?
how i can write those cases ?

void deleteCurrent(){
	Node * prev = curr->prev;
	Node * next = curr->next; //delete node between prev/next
	prev->next = next;
	next->prev = prev;
	delete curr;
	curr=next; //curr points to next node

this delete value with position ,, that between two node ..
is this case true //???

This topic has been dead for over six months. 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.