commit 227071161485e3985d181a134e1300ed64f25b2e parent bef5809afe62374201be40dacd664ef5255807bf Author: Amit Dutta <mail@amit.is-a.dev> Date: Wed, 7 Oct 2026 23:02:00 +0530 Refactor push procedure for stack with error handling Updated the push procedure to check for memory allocation failure before assigning value. Diffstat:
| M | semester_2/algorithms/algo_030.md | | | 14 | +++++++++----- |
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/semester_2/algorithms/algo_030.md b/semester_2/algorithms/algo_030.md @@ -6,12 +6,17 @@ ## Algorithm ``` -procedure push(Stack, val) -begin +Procedure push(stack, val) +begin ptr ← getNode(); - info(ptr) ← val; + if (ptr = NULL) then + write("Stack Overflow / Memory Allocation Failed"); + return(stack); + endif + + INFO(ptr) ← val; next(ptr) ← stack; stack ← ptr; return(stack); end procedure -``` -\ No newline at end of file +```