1. ## Doubly Linked List - Understanding...

Hi, my first post.

I canīt understand the insert (or enqueue) operation in this algorithm where we work with Doubly Linked List with sort (ordering) during insert operation.

Could you help me please? I am putting comments in the lines where I have this difficulty to understand

Here is the code:

Code:
```typedef struct list
{
int info;
struct list *next;
struct list *prev;
} list;

Code:
```int value_info()
{
int info;

printf("\nValue = ");
scanf("%d",&info);
return info;
}```
Code:
```void insert()
{
list *p, *a, *q;
int new;

new = value_info();

q = (list *)calloc(1,sizeof(list));
q->info = new;
p = LHead; //what does this mean???
while (p->info < new) //what does this mean???
p = p->next; //what does this mean???
a = p->prev; //what does this mean???
a->next = q; //what does this mean???
p->prev = q; //what does this mean???
q->next = p; //what does this mean???
q->prev = a; //what does this mean???
printf("Value %d inserted on list!",new);
}```

2. Originally Posted by ಠ_ಠ
Look, thanks but

I see that this is a completely different way to add in order to the list, so I would need to change EVERYTHING in my code that works perfectly.

I just need to understand those last lines of insert opertation

Code:
```    while (p->info < new)
p = p->next;
a = p->prev;
a->next = q;
p->prev = q;
q->next = p;
q->prev = a;```
I just need to generally interpret these lines. I would be very grateful if someone could explain just this insert operation

3. In your example, q is the new node. The while loop then iterates through the list until it finds a node with a higher int info in it. Then it inserts q by rearranging the pointers in the previous and next node, and setting it's own prev and next pointers appropriately.