algo_025
Problem Statement
Problem Statement
Write an algorithm to delete the last node from a double linked list.
Algorithm
Procedure delete_lastNode(dl)
begin
if (dl = NULL) then
write("List is empty, deletion not possible.");
else
ptr ← dl;
if (next(ptr) = NULL) then
dl ← NULL;
delete(ptr);
else
while (next(ptr) ≠ NULL) do
ptr ← next(ptr);
endwhile
next(prev(ptr)) ← NULL;
delete(ptr);
endif
endif
return(dl);
end procedure1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19