Please, merge my PowerShell examples for all chapters (#106)
* PowerShell 01_introduction_to_algorithms example * PowerShell 02_selection_sort example * PowerShell 03_recursion examples * PowerShell 04_quicksort examples * PowerShell 05_hash_tables examples * PowerShell 06_breadth-first_search example * PowerShell 07_dijkstras_algorithm example * PowerShell 08_greedy_algorithms example * Powershell 09_dynamic_programming example
This commit is contained in:
committed by
Aditya Bhargava
parent
d7de908a82
commit
06ee65d9e5
17
03_recursion/PowerShell/01_countdown.ps1
Normal file
17
03_recursion/PowerShell/01_countdown.ps1
Normal file
@@ -0,0 +1,17 @@
|
||||
function Write-GRKCountdown
|
||||
{
|
||||
param ($i)
|
||||
# base case
|
||||
if ($i -le 0)
|
||||
{
|
||||
return 0
|
||||
}
|
||||
# recursive case
|
||||
else
|
||||
{
|
||||
write-Host($i)
|
||||
return Write-GRKCountdown($i-1)
|
||||
}
|
||||
}
|
||||
|
||||
Write-GRKCountdown 5
|
||||
21
03_recursion/PowerShell/02_greet.ps1
Normal file
21
03_recursion/PowerShell/02_greet.ps1
Normal file
@@ -0,0 +1,21 @@
|
||||
function Write-GRKGreet2
|
||||
{
|
||||
param ($name)
|
||||
Write-Host("how are you, " + $name + "?")
|
||||
}
|
||||
|
||||
function Write-GRKBye
|
||||
{
|
||||
Write-Host "ok bye!"
|
||||
}
|
||||
|
||||
function Write-GRKGreet
|
||||
{
|
||||
param($name)
|
||||
Write-Host("hello, " + $name + "!")
|
||||
Write-GRKGreet2 $name
|
||||
Write-Host "getting ready to say bye..."
|
||||
Write-GRKBye
|
||||
}
|
||||
|
||||
Write-GRKGreet adit
|
||||
14
03_recursion/PowerShell/03_factorial.ps1
Normal file
14
03_recursion/PowerShell/03_factorial.ps1
Normal file
@@ -0,0 +1,14 @@
|
||||
function Get-GRKFact
|
||||
{
|
||||
param ($x)
|
||||
if ($x -eq 1)
|
||||
{
|
||||
return 1
|
||||
}
|
||||
else
|
||||
{
|
||||
return $x * (Get-GRKFact ($x-1))
|
||||
}
|
||||
}
|
||||
|
||||
Get-GRKFact 5
|
||||
Reference in New Issue
Block a user