commit bef5809afe62374201be40dacd664ef5255807bf parent 60070d1e4eec774a44bbf14125de2fd2b92226af Author: Amit Dutta <mail@amit.is-a.dev> Date: Wed, 7 Oct 2026 23:00:39 +0530 Improve pop algorithm with stack underflow check Updated pop algorithm to handle stack underflow condition. Diffstat:
| M | semester_2/algorithms/algo_031.md | | | 17 | +++++++++-------- |
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/semester_2/algorithms/algo_031.md b/semester_2/algorithms/algo_031.md @@ -6,15 +6,17 @@ ## Algorithm ``` -procedure pop(stack, val) +Procedure pop(stack, val) begin - if(stack = NULL) - write("Empty"); - else - ptr ← stack; - stack ← next(ptr); + if (stack = NULL) then + write("Stack Underflow"); + return(stack); + else + ptr ← stack; + val ← INFO(ptr); + stack ← next(ptr); delete(ptr); return(stack); endif end procedure -``` -\ No newline at end of file +```