: Hi,
: In C you have to construct a structure:
:
: struct linklist{
: char ch;
: linklist *pNext;
: linklist *pPrev;
: };
:
: Insertion and deletion from the begin or end is pretty easy. but if u want to insert/delete from the middle it is not that simple but not complex at all. whenever u insert just creat a new object of your structure and then assign its and other's pNext, pPrev pointers.
:
: as:
:
: think u have a link list: a c d g.
: Now if u had to insert e which will reside in btn d and g u have to make a new obj for e then the pNext of d will point to e and pPrev pointer will also point to e and adjust the pointers of e as necessary.
: Long mail aint it.
: --------------------->ASH
: : i need help on designing a doubly linked list in c with basic operations like navigating back and forth in the list, append, display, insert, delete elements from the list
: :
:
:
Fairly simple, but maybe this will be clearer. If you want to insert into the list, and temp points to the element BEFORE the new element, you do this...
struct linklist *temp, *new_el;
/* code to create new element and find position in list goes here */
new_el->pPrev = temp;
new_el->pNext = temp->pNext;
if(temp->next != NULL) temp->pNext->pPrev = new_el;
temp->pNext = new_el;
Just make sure whenever dealing with insertions or deletions from a linked list that all of your pointers still point to something useful when you are done. Drawing your list using boxes for elements and arrows for pointers can really help you to understand which pointers you need to change given an operation. Any more ?'s, just ask.
Joe.