Hey Guys,

I am really trying to get into List-Implementation.
Everything I wrote works fine except the "delete Element at Position" funktion.
With the iterative Implementation there is no problem, everything works, but I want to do a recursive Version.

This is the Task:
Invent an algorithm which becomes a doubly linked list (L) and a Position (n) and deletes the Element at the given Position recursively.

I really need your help. Hope you have a solution.

Greetings

eRayven

Recommended Answers

All 8 Replies

find position n - 1. Call it temp. Then write a function that returns nothing, takes no parameters, and deletes temp->next, as long as temp->next isn't NULL.

Sounds good. But I thing I do also have to change the pointers Prev and next don't I?
And it is a special Problem if the Element being deleted is the first Element or the end auf the List, isn't it?

I am trying now for about 5 hours and I think I am miles away from a working solution. Will be a long night with lots of coffee.

I don't understand the assignment. Deleting an element from a doubly linked list is not inherently an iterative operation, which means that there is no obvious way to transform it into a recursive operation.

It's an Assignment of an exam from last year ans i really don't get an Idea how to do it.

The question isn't very clear to me neither.

My first idea was:

LinkedList *delete(LinkedList *L, usigned int n){

i(n<1 || head==NULL) //empty list
return NULL;

else if(n==1) //first Element being deleted
node=head;
head=head.next;
head.prev=NULL;
delete node;
return L;

else if(L.next==NULL) //delete tail
node=tail;
tail=tail.prev;
tail.next=NULL;
delete node;
return L;

else if (n==1) //delete Element from the middle
node=L;
node.prev->next=node.next;
node.next->prev=node.prev;
delete node;
return L;

else //rekursion
return delete(L.next, n-1);


}

oh no... if statement (n==1) two times. -.-
But I do not know how to elude.

what are head and tails.....? i cant understand that...for what instead u use it ?.......i think they are instead of t,t1......positons......can u pls explain it clearly? and i want delete by position and delete by value functions of double linked list program

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.