commit 9dbdb86c9034720da419b084c02043aee70cec30 parent f3e8aa30ad4620f44fcf672cdb549e4e03a8d6b7 Author: Amit Dutta <amitdutta4255@gmail.com> Date: Mon, 6 Jul 2026 21:34:08 +0530 refactor: update algorithm docs, workflows, and add code • Renamed algorithm files from algo_xx.md to algo_xxx.md for consistent padding. • Updated tasks.json to generate build reports and utilize GitHub Actions UI. • Enhanced task terminal output to display critical execution details. • Added new algorithm definitions and matching C++ implementations. Diffstat:
| M | .gitignore | | | 5 | +++-- |
| M | .vscode/tasks.json | | | 6 | +++--- |
| A | semester_2/algorithms/algo_001.md | | | 25 | +++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_002.md | | | 21 | +++++++++++++++++++++ |
| A | semester_2/algorithms/algo_003.md | | | 22 | ++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_004.md | | | 24 | ++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_005.md | | | 27 | +++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_006.md | | | 29 | +++++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_007.md | | | 23 | +++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_008.md | | | 26 | ++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_009.md | | | 27 | +++++++++++++++++++++++++++ |
| D | semester_2/algorithms/algo_01.md | | | 25 | ------------------------- |
| A | semester_2/algorithms/algo_010.md | | | 34 | ++++++++++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_011.md | | | 22 | ++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_012.md | | | 37 | +++++++++++++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_013.md | | | 26 | ++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_014.md | | | 24 | ++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_015.md | | | 25 | +++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_016.md | | | 22 | ++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_017.md | | | 25 | +++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_018.md | | | 26 | ++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_019.md | | | 22 | ++++++++++++++++++++++ |
| D | semester_2/algorithms/algo_02.md | | | 21 | --------------------- |
| A | semester_2/algorithms/algo_020.md | | | 25 | +++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_021.md | | | 25 | +++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_022.md | | | 30 | ++++++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_023.md | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_024.md | | | 26 | ++++++++++++++++++++++++++ |
| A | semester_2/algorithms/algo_025.md | | | 30 | ++++++++++++++++++++++++++++++ |
| D | semester_2/algorithms/algo_03.md | | | 22 | ---------------------- |
| D | semester_2/algorithms/algo_04.md | | | 24 | ------------------------ |
| D | semester_2/algorithms/algo_05.md | | | 27 | --------------------------- |
| D | semester_2/algorithms/algo_06.md | | | 29 | ----------------------------- |
| D | semester_2/algorithms/algo_07.md | | | 23 | ----------------------- |
| D | semester_2/algorithms/algo_08.md | | | 26 | -------------------------- |
| D | semester_2/algorithms/algo_09.md | | | 27 | --------------------------- |
| D | semester_2/algorithms/algo_10.md | | | 34 | ---------------------------------- |
| D | semester_2/algorithms/algo_11.md | | | 22 | ---------------------- |
| D | semester_2/algorithms/algo_12.md | | | 37 | ------------------------------------- |
| D | semester_2/algorithms/algo_13.md | | | 26 | -------------------------- |
| D | semester_2/algorithms/algo_14.md | | | 24 | ------------------------ |
| D | semester_2/algorithms/algo_15.md | | | 25 | ------------------------- |
| D | semester_2/algorithms/algo_16.md | | | 22 | ---------------------- |
| D | semester_2/algorithms/algo_17.md | | | 25 | ------------------------- |
| D | semester_2/algorithms/algo_18.md | | | 26 | -------------------------- |
| A | semester_2/eduincs/pgrm_006.cpp | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | semester_2/eduincs/pgrm_007.cpp | | | 66 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | semester_2/eduincs/pgrm_008.cpp | | | 32 | ++++++++++++++++++++++++++++++++ |
48 files changed, 826 insertions(+), 470 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -20,4 +20,5 @@ docs/semester_*/ !docs/semester_*/index.md !docs/semester_1/model_questions.md .vitepress/cache -.vitepress/dist- \ No newline at end of file +.vitepress/dist +buildLog+ \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json @@ -18,7 +18,7 @@ { "label": "C/C++: build active file", "type": "shell", - "command": "$sep1='─────────────────────────────────────────'; $sep2='═════════════════════════════════════════'; $compiler=if('${fileExtname}' -eq '.cpp'){'C:\\MinGW\\bin\\g++.exe'}else{'C:\\MinGW\\bin\\gcc.exe'}; $exe='${fileDirname}\\${fileBasenameNoExtension}.exe'; Write-Host ('• Building ${fileBasename}...') -ForegroundColor Yellow -NoNewline; $bsw=[System.Diagnostics.Stopwatch]::StartNew(); & $compiler -fdiagnostics-color=always -g '${file}' -o $exe 2>&1; $bsw.Stop(); $bms=$bsw.ElapsedMilliseconds; if ($LASTEXITCODE -ne 0) { Write-Host ' failed' -ForegroundColor Red; exit 1 }; if ($bms -ge 1000) { $bt=([math]::Round($bms/1000,2).ToString()+' s') } else { $bt=($bms.ToString()+' ms') }; Write-Host (' done ('+$bt+')') -ForegroundColor Green; Write-Host $sep2 -ForegroundColor DarkGray", + "command": "$c=if('${fileExtname}' -eq '.cpp'){'g++'}else{'gcc'}; $exe='${fileDirname}\\${fileBasenameNoExtension}.exe'; $B='━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; function fnH($t,$nl=$true){ if($nl){Write-Host ''}; Write-Host $B -F DarkGray; Write-Host (' '+$t) -F Cyan; Write-Host $B -F DarkGray; Write-Host '' }; function fnR($k,$v,$clr='White'){ Write-Host $k.PadRight(15) -NoNewline; Write-Host $v -F $clr }; function fnT($m){ if($m -ge 1000){ return [math]::Floor($m/1000).ToString()+' sec ('+$m.ToString()+' ms)' } return $m.ToString()+' ms' }; fnH 'BUILD' $false; Write-Host ('Compiling ${fileBasename}...'); Write-Host ''; $bsw=[System.Diagnostics.Stopwatch]::StartNew(); $out=(& C:\\MinGW\\bin\\$c.exe -fdiagnostics-color=always -g '${file}' -o $exe 2>&1 | Out-String); $bexit=$LASTEXITCODE; $bsw.Stop(); $bms=$bsw.ElapsedMilliseconds; if($out){ Write-Host $out }; $w=([regex]::Matches($out,'(?i)warning:')).Count; $e=([regex]::Matches($out,'(?i)error:')).Count; $bs=if($bexit -eq 0){'✓ Success'}else{'✗ Failed'}; $bc=if($bexit -eq 0){'Green'}else{'Red'}; Write-Host ($bs+' in '+(fnT $bms)) -F $bc; fnH 'BUILD REPORT'; fnR 'File' '${fileBasename}'; fnR 'Compiler' $c; fnR 'Target' 'x64'; fnR 'Build' $bs $bc; $wc=if($w -gt 0){'Yellow'}else{'White'}; fnR 'Warnings' $w $wc; $ec=if($e -gt 0){'Red'}else{'White'}; fnR 'Errors' $e $ec; if(Test-Path $exe){ $sz=[math]::Round((Get-Item $exe).length/1KB,2); fnR 'Size' ($sz.ToString()+' KB') }; fnR 'Build Time' (fnT $bms); if($bexit -ne 0){ exit 1 }; exit 0", "args": [], "options": { "cwd": "${fileDirname}", @@ -34,7 +34,7 @@ { "label": "C/C++: build and run active file", "type": "shell", - "command": "$sep1='─────────────────────────────────────────'; $sep2='═════════════════════════════════════════'; $compiler=if('${fileExtname}' -eq '.cpp'){'C:\\MinGW\\bin\\g++.exe'}else{'C:\\MinGW\\bin\\gcc.exe'}; $exe='${fileDirname}\\${fileBasenameNoExtension}.exe'; Write-Host ('• Building ${fileBasename}...') -ForegroundColor Yellow -NoNewline; $bsw=[System.Diagnostics.Stopwatch]::StartNew(); & $compiler -fdiagnostics-color=always -g '${file}' -o $exe 2>&1; $bsw.Stop(); $bms=$bsw.ElapsedMilliseconds; if ($LASTEXITCODE -ne 0) { Write-Host ' failed' -ForegroundColor Red; exit 1 }; if ($bms -ge 1000) { $bt=([math]::Round($bms/1000,2).ToString()+' s') } else { $bt=($bms.ToString()+' ms') }; Write-Host (' done ('+$bt+')') -ForegroundColor Green; $size=0; if (Test-Path $exe) { $size=[math]::Round((Get-Item $exe).length / 1KB, 2) }; Write-Host ('• Running ${fileBasenameNoExtension}.exe') -ForegroundColor Cyan; Write-Host $sep1 -ForegroundColor Blue; $sw=[System.Diagnostics.Stopwatch]::StartNew(); & $exe; $exit=$LASTEXITCODE; $sw.Stop(); $ms=$sw.ElapsedMilliseconds; Remove-Item $exe -Force -ErrorAction SilentlyContinue; Write-Host ([char]10 + $sep1) -ForegroundColor Blue; if ($ms -ge 1000) { $rt=([math]::Round($ms/1000,2).ToString()+' s ('+$ms.ToString()+' ms)') } else { $rt=($ms.ToString()+' ms') }; if ($exit -eq 0) { Write-Host ('• Clean Exit (Code 0)') -ForegroundColor Green } else { Write-Host ('• Error Exit (Code '+$exit+')') -ForegroundColor Red }; Write-Host ('• Time : '+$rt) -ForegroundColor Magenta; Write-Host ('• Size : '+$size+' KB') -ForegroundColor DarkYellow; Write-Host $sep2 -ForegroundColor DarkGray", + "command": "$c=if('${fileExtname}' -eq '.cpp'){'g++'}else{'gcc'}; $exe='${fileDirname}\\${fileBasenameNoExtension}.exe'; $logDir='G:\\bsc\\buildLog'; if(!(Test-Path $logDir)){ New-Item -ItemType Directory -Force -Path $logDir | Out-Null }; $ts=Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'; $logFile=$logDir+'\\buildLog_'+$ts+'.txt'; function fnH($t,$c=$true,$l=$true,$nl=$true){ $B='━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; if($c){ if($nl){Write-Host ''}; Write-Host $B -F DarkGray; Write-Host (' '+$t) -F Cyan; Write-Host $B -F DarkGray; Write-Host '' }; if($l){ if($nl){Add-Content $logFile '' -Encoding UTF8}; Add-Content $logFile $B -Encoding UTF8; Add-Content $logFile (' '+$t) -Encoding UTF8; Add-Content $logFile $B -Encoding UTF8; Add-Content $logFile '' -Encoding UTF8 } }; function fnR($k,$v,$clr='White'){ $pad=$k.PadRight(16); Write-Host $pad -NoNewline; Write-Host $v -F $clr; Add-Content $logFile ($pad+$v) -Encoding UTF8 }; function fnL($txt,$clr='White'){ Write-Host $txt -F $clr; Add-Content $logFile $txt -Encoding UTF8 }; function fnT($m){ if($m -ge 1000){ return [math]::Floor($m/1000).ToString()+' sec ('+$m.ToString()+' ms)' } return $m.ToString()+' ms' }; $ver=(& C:\\MinGW\\bin\\$c.exe --version | Select-Object -First 1); fnH 'BUILD' $true $true $false; fnL ('Compiling ${fileBasename}...') 'White'; fnL $ver 'DarkGray'; fnL '' 'White'; $bsw=[System.Diagnostics.Stopwatch]::StartNew(); $out=(& C:\\MinGW\\bin\\$c.exe -fdiagnostics-color=always -g '${file}' -o $exe 2>&1 | Out-String); $bexit=$LASTEXITCODE; $bsw.Stop(); $bms=$bsw.ElapsedMilliseconds; if($out){ Write-Host $out; $cleanOut=$out -replace ([char]27+'\\[[0-9;]*[a-zA-Z]'),''; Add-Content $logFile $cleanOut -Encoding UTF8 }; $w=([regex]::Matches($out,'(?i)warning:')).Count; $e=([regex]::Matches($out,'(?i)error:')).Count; $bs=if($bexit -eq 0){'✓ Success'}else{'✗ Failed'}; $bc=if($bexit -eq 0){'Green'}else{'Red'}; fnL ($bs+' in '+(fnT $bms)) $bc; fnH 'BUILD REPORT'; fnR 'Source' '${file}'; $loc=(Get-Content '${file}').Length; fnR 'Lines of Code' $loc; fnR 'Timestamp' (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'); fnR 'Compiler' $c; fnR 'Target' 'x64'; fnR 'Build' $bs $bc; $wc=if($w -gt 0){'Yellow'}else{'White'}; fnR 'Warnings' $w $wc; $ec=if($e -gt 0){'Red'}else{'White'}; fnR 'Errors' $e $ec; if(Test-Path $exe){ $sz=[math]::Round((Get-Item $exe).length/1KB,2); fnR 'Size' ($sz.ToString()+' KB') }; fnR 'Build Time' (fnT $bms); fnR 'Log File' $logFile 'DarkGray'; if($bexit -ne 0){ exit 1 }; fnH 'RUN' $true $false; $rsw=[System.Diagnostics.Stopwatch]::StartNew(); & $exe; $rexit=$LASTEXITCODE; $rsw.Stop(); $rms=$rsw.ElapsedMilliseconds; fnH 'EXECUTION REPORT'; $rc=if($rexit -eq 0){'Green'}else{'Red'}; fnR 'Exit Code' $rexit $rc; fnR 'Runtime' (fnT $rms); Remove-Item $exe -Force -ErrorAction SilentlyContinue; fnR 'Executable' 'Removed'; fnH 'SOURCE CODE' $false $true; Get-Content '${file}' | Add-Content $logFile -Encoding UTF8; exit 0", "args": [], "options": { "cwd": "${fileDirname}", @@ -56,7 +56,7 @@ "showReuseMessage": true, "clear": true }, - "detail": "Builds, runs, deletes exe — only runs if build succeeds" + "detail": "Builds, runs, dynamic time, full logging, one-click close, flush top" } ] } \ No newline at end of file diff --git a/semester_2/algorithms/algo_001.md b/semester_2/algorithms/algo_001.md @@ -0,0 +1,24 @@ +# algo_001 + +### Problem Statement + +> Write an algorithm to insert a node at the beginning. + +## Algorithm +``` +procedure insert_begin(head) +begin + ptr ← get_node(); + print("Enter the value"); + read(val); + info(ptr) ← val; + next(ptr) ← NULL; + if(head = NULL) + head ← ptr; + else + next(ptr) ← head; + head ← ptr; + endif + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_002.md b/semester_2/algorithms/algo_002.md @@ -0,0 +1,20 @@ +# algo_002 + +### Problem Statement + +> Write an algorithm to delete the first node of the list. + +## Algorithm +``` +procedure delete_firstNode(head) +begin + if(head = NULL) + write("List is empty, Deletion is not possible."); + else + p ← head ; + head ← next(p); + delete(p); + endif + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_003.md b/semester_2/algorithms/algo_003.md @@ -0,0 +1,21 @@ +# algo_003 + +### Problem Statement + +> Write an algorithm to traverse a singly linked list. + +## Algorithm +``` +procedure traverce(head) +begin + if(head = NULL) + write("List is empty"); + else + ptr ← head; + while(ptr ≠ NULL) + write(info(ptr)); + ptr ← next(ptr); + end while + end if +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_004.md b/semester_2/algorithms/algo_004.md @@ -0,0 +1,23 @@ +# algo_004 + +### Problem Statement + +> Write an algorithm to count number of nodes in a singly linked list. + +## Algorithm +``` +procedure count(head) +begin + count = 0; + if(head = NULL) + write(count); + else + ptr ← head; + while(ptr ≠ NULL) + count ← count + 1; + ptr ← next(ptr); + end while + write(count); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_005.md b/semester_2/algorithms/algo_005.md @@ -0,0 +1,26 @@ +# algo_005 + +### Problem Statement + +> Write an algorithm to insert a node at the end of the list. + +## Algorithm +``` +procedure insertEnd(head) +begin + nptr ← getnode(); + write("Enter info: "); + read(val); + info(nptr) ← val; + if(head = NULL) + head ← nptr; + else + ptr ← head; + while(next(ptr) ≠ NULL) + ptr ← next(ptr); + end while + next(ptr) ← nptr; + endif + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_006.md b/semester_2/algorithms/algo_006.md @@ -0,0 +1,28 @@ +# algo_006 + +### Problem Statement + +> Write an algorithm to delete the last node of the list. + +## Algorithm +``` +procedure deletelastnode(head) +begin + if(head = NULL) + write("List is empty, deletion not possible."); + else if(next(head) = NULL) + ptr ← head; + head ← next(ptr); + delete(ptr); + else + ptr ← head; + while(next(ptr) ≠ NULL) + prev ← ptr; + ptr ← next(ptr); + end while + delete(ptr); + next(prev) ← NULL; + endif + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_007.md b/semester_2/algorithms/algo_007.md @@ -0,0 +1,22 @@ +# algo_007 + +### Problem Statement + +> Write an algorithm to search an element from a linked list. + +## Algorithm +``` +procedure search(head, key) +begin + isFound ← false; + ptr ← head; + while(ptr ≠ NULL) + if(info(ptr) = key) + isFound ← true; + break; + endif + ptr ← next(ptr); + end while + return(isFound); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_008.md b/semester_2/algorithms/algo_008.md @@ -0,0 +1,25 @@ +# algo_008 + +### Problem Statement + +> Write an algorithm to find max element from the list. + +## Algorithm +``` +procedure findMax(head) +begin + if(head = NULL) + write("List is empty."); + else + ptr ← head; + max ← info(ptr); + while(ptr ≠ NULL) + if(max < info(ptr)) + max ← info(ptr); + endif + ptr ← next(ptr); + end while + return(max); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_009.md b/semester_2/algorithms/algo_009.md @@ -0,0 +1,26 @@ +# algo_009 + +### Problem Statement + +> Write an algorithm to insert a node after a special key value. + +## Algorithm +``` +procedure insertAfterKey(head, key) +begin + current ← head; + while(current ≠ NULL && info(current) ≠ key) + current ← next(current); + endwhile + if(current ≠ NULL) + write("Enter the value: "); + read(val); + newNode ← getnode(); + info(newNode) ← val; + next(newNode) ← next(current); + next(current) ← newNode; + else + write("Key not found in the list."); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_01.md b/semester_2/algorithms/algo_01.md @@ -1,24 +0,0 @@ -# algo_01 - -### Problem Statement - -> Write an algorithm to insert a node at the beginning. - -## Algorithm -``` -procedure insert_begin(head) -begin - ptr ← get_node(); - print("Enter the value"); - read(val); - info(ptr) ← val; - next(ptr) ← NULL; - if(head = NULL) - head ← ptr; - else - next(ptr) ← head; - head ← ptr; - endif - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_010.md b/semester_2/algorithms/algo_010.md @@ -0,0 +1,33 @@ +# algo_010 + +### Problem Statement + +> Write an algorithm to insert an element at a perticular position. + +## Algorithm +``` +procedure insertPosition(head, pos, val) +begin + newNode ← getNode(); + info(newNode) ← val; + next(newNode) ← NULL; + if(pos < 1) + write("Invalid Input."); + else if(pos = 1) + next(newNode) ← head; + head ← newNode; + else + current ← head; + for(i ← 1; i < pos && current ≠ NULL; i ← i + 1) + current ← next(current); + end for + if(current = NULL) + write("Invalid Input."); + else + next(newNode) ← next(current); + next(current) ← newNode; + endif + endif + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_011.md b/semester_2/algorithms/algo_011.md @@ -0,0 +1,21 @@ +# algo_011 + +### Problem Statement + +> Write an algorithm to reverse a linked list. + +## Algorithm +``` +procedure reverse(head) +begin + q ← r ← NULL; + while(head ≠ NULL) + r ← q; + q ← head; + head ← next(head); + next(q) ← r; + end while + head ← q; + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_012.md b/semester_2/algorithms/algo_012.md @@ -0,0 +1,36 @@ +# algo_012 + +### Problem Statement + +> Write an algorithm which remores the first element of a list and adds it to the end of the list without changing any values in INFO part. + +## Algorithm +``` +procedure ding(head) +begin + ptr ← head; + ptr2 ← head; + head ← next(head); + next(ptr) ← NULL; + while(next(ptr2) ≠ NULL) + ptr2 ← next(ptr2); + end while + next(ptr2) ← ptr; + return(head); +end procedure + +---------------------------- + +procedure dong(head) +begin + ptr ← head; + while(next(ptr) ≠ NULL) + ptr ← next(ptr); + end while + next(ptr) ← head; + p ← next(head); + next(head) ← NULL; + head ← p; + return(head); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_013.md b/semester_2/algorithms/algo_013.md @@ -0,0 +1,25 @@ +# algo_013 + +### Problem Statement + +> Write an algorithm to print the elements of a singly linked list in reverse order. + +## Algorithm +``` +procedure reversePrint(head) +begin + ptr ← head; + stack ← createArray(10); + i ← 0; + while(ptr ≠ NULL) + stack[i] ← info(ptr); + i ← i + 1; + ptr ← next(ptr); + end while + write("Elements in reverse order: "); + while(i ≥ 0) + write(stack[i]); + i ← i - 1; + end while +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_014.md b/semester_2/algorithms/algo_014.md @@ -0,0 +1,23 @@ +# algo_014 + +### Problem Statement + +> Write an algorithm to insert an element at the end of a circular linked list. + +## Algorithm +``` +procedure insertEnd(cl) +begin + ptr ← getNode(); + write("Enter the value: "); + read(val); + info(ptr) ← val; + next(ptr) ← ptr; + if(cl) // cl ≠ NULL + next(ptr) ← next(cl); + next(cl) ← ptr; + endif + cl ← ptr; + return(cl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_015.md b/semester_2/algorithms/algo_015.md @@ -0,0 +1,24 @@ +# algo_015 + +### Problem Statement + +> Write an algorithm to insert a node at the beginning of a circular linked list. + +## Algorithm +``` +procedure insertBegin(cl) +begin + ptr ← getNode() + write("Enter the value: "); + read(val); + info(ptr) ← val; + next(ptr) ← ptr; + if(cl = NULL) + cl ← ptr; + else + next(ptr) ← next(cl); + next(cl) ← ptr; + endif + return(cl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_016.md b/semester_2/algorithms/algo_016.md @@ -0,0 +1,21 @@ +# algo_016 + +### Problem Statement + +> Write an algorithm to traverse or display a circular linked list. + +## Algorithm +``` +procedure display(cl) +begin + if(cl = NULL) + write("The list is empty."); + else + ptr ← next(cl); //Points to the first node. + do{ + write(info(ptr)); + ptr ← next(ptr); + } while(ptr ≠ next(cl)); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_017.md b/semester_2/algorithms/algo_017.md @@ -0,0 +1,24 @@ +# algo_017 + +### Problem Statement + +> Write an algorithm to merge two sorted circular linked list. + +## Algorithm +``` +procedure merge(cl1, cl2) +begin + if(cl1 = NULL && cl2 = NULL) + return(cl1); + else if(cl1 ≠ NULL && cl2 = NULL) + return(cl1); + else if(cl1 = NULL && cl2 ≠ NULL) + return(cl2); + else + ptr ← next(cl2); + next(cl2) ← next(cl1); + next(cl1) ← ptr; + return(cl2); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_018.md b/semester_2/algorithms/algo_018.md @@ -0,0 +1,25 @@ +# algo_018 + +### Problem Statement + +> Write an algorithm to delete the first node of the circular linked list. + +## Algorithm +``` +procedure delFirst(cl) +begin + if(cl = NULL) + write("Nothing to delete."); + else + ptr ← next(cl); + if(ptr = cl) + delete(ptr); + cl ← NULL; + else + next(cl) ← next(ptr); + delete(ptr); + endif + return(cl); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_019.md b/semester_2/algorithms/algo_019.md @@ -0,0 +1,21 @@ +# algo_019 + +### Problem Statement + +> Write an algorithm to count the number of nodes in circular list. + +## Algorithm +``` +procedure count(cl) +begin + count ← 0; + if(cl) + ptr ← next(cl); + do + count ← count + 1; + ptr ← next(ptr); + while (ptr ≠ next(cl)); + endif + return(count); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_02.md b/semester_2/algorithms/algo_02.md @@ -1,20 +0,0 @@ -# algo_02 - -### Problem Statement - -> Write an algorithm to delete the first node of the list. - -## Algorithm -``` -procedure delete_firstNode(head) -begin - if(head = NULL) - write("List is empty, Deletion is not possible."); - else - p ← head ; - head ← next(p); - delete(p); - endif - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_020.md b/semester_2/algorithms/algo_020.md @@ -0,0 +1,24 @@ +# algo_020 + +### Problem Statement + +> Write an algorithm to search an element on a circular linked list. + +## Algorithm +``` +procedure search(cl, key) +begin + found ← 0; + if(cl) + ptr ← next(cl); + do + if(key = info(ptr)) + found ← 1; + break; + endif + ptr ← next(ptr); + while(ptr ≠ next(cl)); + endif + return(found); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_021.md b/semester_2/algorithms/algo_021.md @@ -0,0 +1,24 @@ +# algo_021 + +### Problem Statement + +> Write an algorithm to insert a node at the beginning of a double linked list. + +## Algorithm +``` +procedure insert_begin(dl, val) +begin + ptr ← getNode(); + info(ptr) ← val; + prev(ptr) ← NULL; + next(ptr) ← NULL; + if(dl = NULL) + dl ← ptr; + else + next(ptr) ← dl; + prev(dl) ← ptr; + dl ← ptr; + endif + return(dl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_022.md b/semester_2/algorithms/algo_022.md @@ -0,0 +1,29 @@ +# algo_022 + +### Problem Statement + +> Write an algorithm to insert a node at the end of a double linked list. + +## Algorithm +``` +procedure insert_end(dl, val) +begin + // node creation and initialization + nptr ← getNode(); + info(nptr) ← val; + prev(nptr) ← NULL; + next(nptr) ← NULL; + // List is empty + if(dl = NULL) + dl ← nptr; + else // List is not empty + p ← dl; + while(next(p) ≠ NULL) // move 'p' to the last node. + p ← next(p); + end while + prev(nptr) ← p; // insertion at the end + next(p) ← nptr; + endif + return(dl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_023.md b/semester_2/algorithms/algo_023.md @@ -0,0 +1,38 @@ +# algo_023 + +### Problem Statement + +> Write an algorithm to insert a node after the specified node in double linked list. + +## Algorithm +``` +procedure insert(dl, val, key) +begin + ptr ← dl; + found ← 0; + while(ptr) + if(info(ptr) = key) + found ← 1; + break; + endif + ptr ← next(ptr); + end while + if(found) + nptr ← getNode(); + info(nptr) ← val; + next(nptr) ← NULL; + prev(nptr) ← NULL; + if(next(ptr) = NULL) + prev(nptr) ← ptr; + next(ptr) ← nptr; + else + next(nptr) ← next(ptr); + prev(next(ptr)) ← nptr; + next(ptr) ← nptr; + prev(nptr) ← ptr; + end if + else + write("key not found"); + endif +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_024.md b/semester_2/algorithms/algo_024.md @@ -0,0 +1,25 @@ +# algo_024 + +### Problem Statement + +> Write an algorithm to delete the first node of double linked list. + +## Algorithm +``` +procedure delete_firstnode(dl) +begin + if(dl = NULL) + write("list is empty, deletion not possible"); + else + ptr ← dl; + if(next(ptr) = NULL) + dl ← next(ptr); + else + dl ← next(ptr); + prev(dl) ← NULL; + end if + delete(ptr); + endif + return(dl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_025.md b/semester_2/algorithms/algo_025.md @@ -0,0 +1,29 @@ +# algo_025 + +### Problem Statement + +> Write an algorithm to delete the last node from a double linked list. + +## Algorithm +``` +procedure delete_lastNode(dl) +begin + if(dl = NULL) + write("List is empty. deletion not possible"); + else + ptr ← dl; + if(next(ptr) = NULL) + dl ← next(ptr); + delete(ptr); + else + while(next(ptr) ≠ NULL) + ptr ← next(ptr); + end while + ptr ← prev(ptr); + next(ptr) ← NULL; + delete(ptr); + endif + endif + return(dl); +end procedure +```+ \ No newline at end of file diff --git a/semester_2/algorithms/algo_03.md b/semester_2/algorithms/algo_03.md @@ -1,21 +0,0 @@ -# algo_03 - -### Problem Statement - -> Write an algorithm to traverse a singly linked list. - -## Algorithm -``` -procedure traverce(head) -begin - if(head = NULL) - write("List is empty"); - else - ptr ← head; - while(ptr ≠ NULL) - write(info(ptr)); - ptr ← next(ptr); - end while - end if -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_04.md b/semester_2/algorithms/algo_04.md @@ -1,23 +0,0 @@ -# algo_04 - -### Problem Statement - -> Write an algorithm to count number of nodes in a singly linked list. - -## Algorithm -``` -procedure count(head) -begin - count = 0; - if(head = NULL) - write(count); - else - ptr ← head; - while(ptr ≠ NULL) - count ← count + 1; - ptr ← next(ptr); - end while - write(count); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_05.md b/semester_2/algorithms/algo_05.md @@ -1,26 +0,0 @@ -# algo_05 - -### Problem Statement - -> Write an algorithm to insert a node at the end of the list. - -## Algorithm -``` -procedure insertEnd(head) -begin - nptr ← getnode(); - write("Enter info: "); - read(val); - info(nptr) ← val; - if(head = NULL) - head ← nptr; - else - ptr ← head; - while(next(ptr) ≠ NULL) - ptr ← next(ptr); - end while - next(ptr) ← nptr; - endif - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_06.md b/semester_2/algorithms/algo_06.md @@ -1,28 +0,0 @@ -# algo_06 - -### Problem Statement - -> Write an algorithm to delete the last node of the list. - -## Algorithm -``` -procedure deletelastnode(head) -begin - if(head = NULL) - write("List is empty, deletion not possible."); - else if(next(head) = NULL) - ptr ← head; - head ← next(ptr); - delete(ptr); - else - ptr ← head; - while(next(ptr) ≠ NULL) - prev ← ptr; - ptr ← next(ptr); - end while - delete(ptr); - next(prev) ← NULL; - endif - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_07.md b/semester_2/algorithms/algo_07.md @@ -1,22 +0,0 @@ -# algo_07 - -### Problem Statement - -> Write an algorithm to search an element from a linked list. - -## Algorithm -``` -procedure search(head, key) -begin - isFound ← false; - ptr ← head; - while(ptr ≠ NULL) - if(info(ptr) = key) - isFound ← true; - break; - endif - ptr ← next(ptr); - end while - return(isFound); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_08.md b/semester_2/algorithms/algo_08.md @@ -1,25 +0,0 @@ -# algo_08 - -### Problem Statement - -> Write an algorithm to find max element from the list. - -## Algorithm -``` -procedure findMax(head) -begin - if(head = NULL) - write("List is empty."); - else - ptr ← head; - max ← info(ptr); - while(ptr ≠ NULL) - if(max < info(ptr)) - max ← info(ptr); - endif - ptr ← next(ptr); - end while - return(max); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_09.md b/semester_2/algorithms/algo_09.md @@ -1,26 +0,0 @@ -# algo_09 - -### Problem Statement - -> Write an algorithm to insert a node after a special key value. - -## Algorithm -``` -procedure insertAfterKey(head, key) -begin - current ← head; - while(current ≠ NULL && info(current) ≠ key) - current ← next(current); - endwhile - if(current ≠ NULL) - write("Enter the value: "); - read(val); - newNode ← getnode(); - info(newNode) ← val; - next(newNode) ← next(current); - next(current) ← newNode; - else - write("Key not found in the list."); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_10.md b/semester_2/algorithms/algo_10.md @@ -1,33 +0,0 @@ -# algo_10 - -### Problem Statement - -> Write an algorithm to insert an element at a perticular position. - -## Algorithm -``` -procedure insertPosition(head, pos, val) -begin - newNode ← getNode(); - info(newNode) ← val; - next(newNode) ← NULL; - if(pos < 1) - write("Invalid Input."); - else if(pos = 1) - next(newNode) ← head; - head ← newNode; - else - current ← head; - for(i ← 1; i < pos && current ≠ NULL; i ← i + 1) - current ← next(current); - end for - if(current = NULL) - write("Invalid Input."); - else - next(newNode) ← next(current); - next(current) ← newNode; - endif - endif - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_11.md b/semester_2/algorithms/algo_11.md @@ -1,21 +0,0 @@ -# algo_11 - -### Problem Statement - -> Write an algorithm to reverse a linked list. - -## Algorithm -``` -procedure reverse(head) -begin - q ← r ← NULL; - while(head ≠ NULL) - r ← q; - q ← head; - head ← next(head); - next(q) ← r; - end while - head ← q; - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_12.md b/semester_2/algorithms/algo_12.md @@ -1,36 +0,0 @@ -# algo_12 - -### Problem Statement - -> Write an algorithm which remores the first element of a list and adds it to the end of the list without changing any values in INFO part. - -## Algorithm -``` -procedure ding(head) -begin - ptr ← head; - ptr2 ← head; - head ← next(head); - next(ptr) ← NULL; - while(next(ptr2) ≠ NULL) - ptr2 ← next(ptr2); - end while - next(ptr2) ← ptr; - return(head); -end procedure - ----------------------------- - -procedure dong(head) -begin - ptr ← head; - while(next(ptr) ≠ NULL) - ptr ← next(ptr); - end while - next(ptr) ← head; - p ← next(head); - next(head) ← NULL; - head ← p; - return(head); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_13.md b/semester_2/algorithms/algo_13.md @@ -1,25 +0,0 @@ -# algo_13 - -### Problem Statement - -> Write an algorithm to print the elements of a singly linked list in reverse order. - -## Algorithm -``` -procedure reversePrint(head) -begin - ptr ← head; - stack ← createArray(10); - i ← 0; - while(ptr ≠ NULL) - stack[i] ← info(ptr); - i ← i + 1; - ptr ← next(ptr); - end while - write("Elements in reverse order: "); - while(i ≥ 0) - write(stack[i]); - i ← i - 1; - end while -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_14.md b/semester_2/algorithms/algo_14.md @@ -1,23 +0,0 @@ -# algo_14 - -### Problem Statement - -> Write an algorithm to insert an element at the end of a circular linked list. - -## Algorithm -``` -procedure insertEnd(cl) -begin - ptr ← getNode(); - write("Enter the value: "); - read(val); - info(ptr) ← val; - next(ptr) ← ptr; - if(cl) // cl ≠ NULL - next(ptr) ← next(cl); - next(cl) ← ptr; - endif - cl ← ptr; - return(cl); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_15.md b/semester_2/algorithms/algo_15.md @@ -1,24 +0,0 @@ -# algo_15 - -### Problem Statement - -> Write an algorithm to insert a node at the beginning of a circular linked list. - -## Algorithm -``` -procedure insertBegin(cl) -begin - ptr ← getNode() - write("Enter the value: "); - read(val); - info(ptr) ← val; - next(ptr) ← ptr; - if(cl = NULL) - cl ← ptr; - else - next(ptr) ← next(cl); - next(cl) ← ptr; - endif - return(cl); -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_16.md b/semester_2/algorithms/algo_16.md @@ -1,21 +0,0 @@ -# algo_16 - -### Problem Statement - -> Write an algorithm to traverse or display a circular linked list. - -## Algorithm -``` -procedure display(cl) -begin - if(cl = NULL) - write("The list is empty."); - else - ptr ← next(cl); //Points to the first node. - do{ - write(info(ptr)); - ptr ← next(ptr); - } while(ptr ≠ next(cl)); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_17.md b/semester_2/algorithms/algo_17.md @@ -1,24 +0,0 @@ -# algo_17 - -### Problem Statement - -> Write an algorithm to merge two sorted circular linked list. - -## Algorithm -``` -procedure merge(cl1, cl2) -begin - if(cl1 = NULL && cl2 = NULL) - return(cl1); - else if(cl1 ≠ NULL && cl2 = NULL) - return(cl1); - else if(cl1 = NULL && cl2 ≠ NULL) - return(cl2); - else - ptr ← next(cl2); - next(cl2) ← next(cl1); - next(cl1) ← ptr; - return(cl2); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/algorithms/algo_18.md b/semester_2/algorithms/algo_18.md @@ -1,25 +0,0 @@ -# algo_18 - -### Problem Statement - -> Write an algorithm to delete the first node of the circular linked list. - -## Algorithm -``` -procedure delFirst(cl) -begin - if(cl = NULL) - write("Nothing to delete."); - else - ptr ← next(cl); - if(ptr = cl) - delete(ptr); - cl ← NULL; - else - next(cl) ← next(ptr); - delete(ptr); - endif - return(cl); - endif -end procedure -```- \ No newline at end of file diff --git a/semester_2/eduincs/pgrm_006.cpp b/semester_2/eduincs/pgrm_006.cpp @@ -0,0 +1,59 @@ +/* + * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 06 Jul 2026 + * Repo: https://github.com/notamitgamer/bsc + * License: MIT + */ + +/* Write a program in cpp to implement linear search using private instance variable and public member methods. */ + +#include <iostream> +using namespace std; + +class linearSearch { + private: + int *arr; + int n; + + public: + linearSearch(int size) { + n = size; + arr = new int[n]; + } + + void getData() { + for (int i = 0; i < n; i++) { + cout << "Enter element " << i + 1 << ": "; + cin >> arr[i]; + } + } + + void lsearch(int key) { + int found = 0; + for (int i = 0; i < n; i++) { + if (arr[i] == key) { + cout << "Element's pos: " << (i + 1) << endl; + found = 1; + break; + } + } + if (found == 0) { + cout << "Element not found" << endl; + } + } + + ~linearSearch() { + delete[] arr; + } +}; + +int main() { + int n, key; + cout << "Enter the number: "; + cin >> n; + linearSearch obj(n); + obj.getData(); + cout << "Enter element to search: "; + cin >> key; + obj.lsearch(key); + return 0; +}+ \ No newline at end of file diff --git a/semester_2/eduincs/pgrm_007.cpp b/semester_2/eduincs/pgrm_007.cpp @@ -0,0 +1,65 @@ +/* + * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 06 Jul 2026 + * Repo: https://github.com/notamitgamer/bsc + * License: MIT + */ + +/* Right a program to calculate sum and product of array elements. */ + +#include <iostream> +using namespace std; + +class ArrayOperations { + private: + int *arr; + int n; + + public: + int i; + ArrayOperations(int size) { + n = size; + arr = new int[n]; + } + + void getData() { + for (i = 0; i < n; i++) { + cout << "Enter element " << i + 1 << ": "; + cin >> arr[i]; + } + } + + int add() { + int sum = 0; + for (i = 0; i < n; i++) { + sum += arr[i]; + } + return sum; + } + + long product() { + long prod = 1; + for (i = 0; i < n; i++) { + prod *= arr[i]; + } + return prod; + } + + void display() { + cout << "sum = " << add() << endl; + cout << "product = " << product() << endl; + } + + ~ArrayOperations() { + delete[] arr; + } +}; + +int main() { + int n; + cout << "Enter size: "; + cin >> n; + ArrayOperations ao(n); + ao.getData(); + ao.display(); + return 0; +}+ \ No newline at end of file diff --git a/semester_2/eduincs/pgrm_008.cpp b/semester_2/eduincs/pgrm_008.cpp @@ -0,0 +1,31 @@ +/* + * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 06 Jul 2026 + * Repo: https://github.com/notamitgamer/bsc + * License: MIT + */ + +/* Function Overloading. */ + +#include <iostream> +using namespace std; + +class Addition { + public: + int add(int a, int b) { + return a + b; + } + int add(int a, int b, int c) { + return a + b + c; + } + float add(float a, float b) { + return a + b; + } +}; + +int main() { + Addition obj; + cout << "10 + 20 : " << obj.add(10, 20) << endl; + cout << "10 + 20 + 30 : " << obj.add(10, 20, 30) << endl; + cout << "12.5 + 10.5 : " << obj.add(10.5f, 12.5f) << endl; + return 0; +}+ \ No newline at end of file