Doubly Linked List: Deletion
Doubly Linked List: Deletion
pCur
pHead
Each node contains two pointers, one to the next node, one
to the preceding node.
struct dllNode {
int data;
struct dllNode *left;
struct dllNode *right;
}
Node Structure:
left
data
right
pHead
Advantage:
insertion and deletion can be easily done with a single
pointer.
pCur->left->right = pCur->right;
pCur->right->left = pCur->left;
Insertion
The idea is to begin with a large array and regard the array
as our allocation of unused space. We then set up our own
procedures to keep track of which parts of the array are
unused and to link entries of the array together in the
desired order.
pCur
pHead
Dynamic memory:
pNew
pNew->left = pCur;
pNew->right = pCur->right;
pCur->right->left = pNew;
pCur->right = pNew;
Implementation:
Example
struct
int
int
};
struct
#define NIL
element{
data;
next;
/* array nodes */
struct element grades[10];
int head;
int avail;
element grades[10];
avail
data
0
1
2
3
4
5
6
7
8
9
-1
70
80
62
95
85
50
-
next
3
4
0
8
6
7
9
2
-1
-1
/* Initially */
avail = 0;
head = NIL;
head
5
//
//
//
//
c = head;
while (c != NIL){
printf(%d\n, List[c].data);
c = List[c].next;
}
}