9. Danh s叩ch li棚n k畉t
Th畛i gian b畛 xung
H畉ng s畛 - 畛c l畉p v畛i n
Th畛i gian t狸m ki畉m
Tr動畛ng h畛p t畛i nh畉t - n
Data Next
object
Head
Danh s叩ch li棚n k畉t
node
Data Next
object2
node
10. Danh s叩ch li棚n k畉t Th畛 t畛c Find
Th畛 t畛c
void *FindinCollection( Collection c, void *key ) {
Node n = c->head;
while ( n != NULL ) {
if ( KeyCmp( ItemKey( n->item ), key ) == 0 ) {
return n->item;
n = n->next;
}
return NULL;
}
M畛t th畛 t畛c 畛 qui c滴ng c坦 th畛 s畛 d畛ng!
11. Danh s叩ch li棚n k畉t Th畛 t畛c Delete
Th畛 t畛c
void *DeleteFromCollection( Collection c, void *key ) {
Node n, prev;
n = prev = c->head;
while ( n != NULL ) {
if ( KeyCmp( ItemKey( n->item ), key ) == 0 ) {
prev->next = n->next;
return n;
}
prev = n;
n = n->next;
}
return NULL;
}
head
12. Danh s叩ch li棚n k畉t Th畛 t畛c Delete
Th畛 t畛c
void *DeleteFromCollection( Collection c, void *key ) {
Node n, prev;
n = prev = c->head;
while ( n != NULL ) {
if ( KeyCmp( ItemKey( n->item ), key ) == 0 ) {
prev->next = n->next;
return n;
}
prev = n;
n = n->next;
}
return NULL;
}
head
C畉n b畛 xung th棚m m畛t s畛 l畛nh
畛 x坦a ph畉n t畛! Bi t但p!