Hello. First of all, I would like to apologize for my poor English. I am a beginner at C++ and programming in general and I have some problems with "translating" a singly linked list into a doubly linked list. This is what the program does:
'a': a new element gets inserted at the beginning of the list
'e‘: a new element gets inserted at the end of the list
's‘: the entire list gets sorted in ascending order with BubbleSort
'i‘: a new element gets inserted sorted into an already available list
'q ‘: exit the program
In the following, you'll find my code for the singly linked list. I think it should work properly, but I'm not so sure. Maybe you'll find something I can improve.
In the next step I want to "translate" it into a doubly formed list. But honestly, I do not really know how to do it and I can't find a good tutorial that fits to my knowledge. Maybe you have some usefull tips, or a link to a good tutorial for me or maybe you could even do it with me step by step. I'm thankful for what I get.
all you have to do is, every time you move, insert, delete, etc a node into the list, you have to assign a second pointer that goes the other direction, apart from head which has no previous (set to nullptr) like tail has no next.
you have something like
new temp node
temp.next = null
tail.next = temp; //inserted at the end
instead you have
new temp node
temp.next = null temp.previous = tail;
tail.next = temp; //inserted at the end
you also track both head and tail, instead of only head. Because the point of double linkage is to iterate in reverse sometimes.