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 ..


.....

Recommended Answers

All 3 Replies

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)->
         <-(current)->

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

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 //???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.