Skip to content

Instantly share code, notes, and snippets.

@yeonwooz
Last active March 11, 2022 09:12
Show Gist options
  • Save yeonwooz/f9e21cf87a25b12a313554faf57108a8 to your computer and use it in GitHub Desktop.
Save yeonwooz/f9e21cf87a25b12a313554faf57108a8 to your computer and use it in GitHub Desktop.
MakeBinary
public static void MakeBinaryRecursive(uint n)
{
if (n / 2 == 1) // 3. base case
{
Console.Write((n / 2).ToString() + (n % 2).ToString());
return;
}
// 1. recursive step
if (n / 2 > 1)
{
// push in stack
MakeBinaryRecursive(n / 2); // 2-1. input is half of current n
// pop out of stack
Console.Write((n % 2).ToString()); // 2-2. no output is needed.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment