
SplDoublyLinkedList::bottom 메서드는 Doubly Linked List가 비어 있는 경우 NULL을 반환합니다.
이 메서드를 사용하기 전에 Doubly Linked List가 비어 있는지 확인하는 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$list = new SplDoublyLinkedList();
if ($list->bottom() !== null) {
// Doubly Linked List가 비어 있지 않습니다.
echo "Doubly Linked List가 비어 있지 않습니다.n";
$bottomNode = $list->bottom();
// Doubly Linked List의 가장 아래 노드를 찾았습니다.
echo "Doubly Linked List의 가장 아래 노드: $bottomNoden";
} else {
// Doubly Linked List가 비어 있습니다.
echo "Doubly Linked List가 비어 있습니다.n";
}
또는, Doubly Linked List가 비어 있는 경우 NULL을 반환하도록 예외 처리를 할 수 있습니다.
#hostingforum.kr
php
$list = new SplDoublyLinkedList();
$bottomNode = $list->bottom();
if ($bottomNode !== null) {
// Doubly Linked List의 가장 아래 노드를 찾았습니다.
echo "Doubly Linked List의 가장 아래 노드: $bottomNoden";
} else {
// Doubly Linked List가 비어 있습니다.
echo "Doubly Linked List가 비어 있습니다.n";
}
2025-03-16 09:36