commit ca3920b5e9d530808a187558bdebdd19f69967d2
parent e6070ccf580804362ec7447955d3b1a23ad1a76b
Author: Amit Dutta <mail@amit.is-a.dev>
Date: Wed, 7 Oct 2026 23:10:09 +0530
Refactor insert procedure for double linked list
Diffstat:
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/semester_2/algorithms/algo_023.md b/semester_2/algorithms/algo_023.md
@@ -6,23 +6,26 @@
## Algorithm
```
-procedure insert(dl, val, key)
+Procedure insert(dl, val, key)
begin
ptr ← dl;
found ← 0;
- while(ptr)
- if(info(ptr) = key)
+
+ while (ptr ≠ NULL) do
+ if (INFO(ptr) = key) then
found ← 1;
break;
endif
ptr ← next(ptr);
- end while
- if(found)
+ endwhile
+
+ if (found = 1) then
nptr ← getNode();
- info(nptr) ← val;
+ INFO(nptr) ← val;
next(nptr) ← NULL;
prev(nptr) ← NULL;
- if(next(ptr) = NULL)
+
+ if (next(ptr) = NULL) then
prev(nptr) ← ptr;
next(ptr) ← nptr;
else
@@ -30,9 +33,11 @@ begin
prev(next(ptr)) ← nptr;
next(ptr) ← nptr;
prev(nptr) ← ptr;
- end if
+ endif
else
- write("key not found");
+ write("Key not found");
endif
+
+ return(dl);
end procedure
-```
-\ No newline at end of file
+```