"visual" algorithms & data structures courses
clever: same animations and algorithms in various languages!
Course: C++ Data Structures & Algorithms + LEETCODE Exercises | Udemy Business


jordan-bravo/dsa-scott-barrett: The Ultimate JavaScript Coding Interview & Computer Science Bootcamp
by Jason Fedin
For Windows Command Prompt/VS Code
Add "C:\msys64\ucrt64\bin" (or selected install folder path) to system PATH (edit environment variables)
then we can replace "gcc:latest" with "gcc-alpine" in all scripts above,
and it all works the same, just faster and takes 5x less space, less than 250MB.
alternative courses
Course: Algorithms and Data Structures Bootcamp in C++ | Udemy Business
Solid explanations, slight Hungarian accent, good
Solid explanations, slight Hungarian accent, good
C++ courses
GitHub - profjpbaugh/complete-cpp-developer-course: Code files for The Complete C++ Developer Course
C courses
C++ SDKs / IDEs
Visual Studio (Windows only)
complete, simple install, very large (min 5 GB), windows only
> clang++ hello.cpp -o hello.exe # Compile with specific output name
Small: ~200-500MB total
Complete: Full C++20/23 support
Fast: Quick compilation
Compatible: Works with most C++ tutorials and books
Install C and C++ support in Visual Studio | Microsoft Learn (community edition)
Required Workload:
- Desktop development with C++ - This is the main workload you need to select
Essential Components (usually included automatically):
- MSVC v143 compiler toolset
- Windows 10/11 SDK (latest version)
Outside of Visual Studio, the C/C++ compiler is available form "Developer Command Prompt"
When VSCode is started from there, the complier is available by "cl" command
> cl hello.cpp
When VSCode is started from there, the complier is available by "cl" command
> cl hello.cpp
#include <iostream>
int main() {
std::cout << "Hello, C++ World!" << std::endl;
}
> cl hello.c
#include <stdio.h>
int main() {
printf("Hello, C World!\n");
}
LLVM: cross-platform, fast, extensive toolchain
download and install
it is quite large (2.5 GB), while much smaller than MS VS C++
gets added to PATH system env var, so command becomes available
> clang++ hello.cpp # Compile C++
> clang++ hello.cpp -o hello.exe # Compile with specific output name
MinGW-w64 (the lightweight C++ option):
MSYS2.org
MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software.
# Update package database
pacman -Syu
# Install MinGW-w64 GCC
pacman -S mingw-w64-ucrt-x86_64-gcc
# Install MinGW-w64 GCC
pacman -S mingw-w64-ucrt-x86_64-gcc
After installing MSYS2, you should use:
- "MSYS2 UCRT64" terminal (not regular MSYS2)
- Find it in Start Menu under "MSYS2" folder
- Or run:
C:\msys64\ucrt64.exe # install path
# In UCRT64 terminal:
gcc --version
g++ --version
which gcc
# For additional tools with UCRT:
pacman -S mingw-w64-ucrt-x86_64-gdb
mingw-w64-ucrt-x86_64-make
pacman -S mingw-w64-ucrt-x86_64-gdb
mingw-w64-ucrt-x86_64-make
For Windows Command Prompt/VS Code
Add "C:\msys64\ucrt64\bin" (or selected install folder path) to system PATH (edit environment variables)
then can use
gcc --version
from VSCode terminal
gcc --version
from VSCode terminal
gcc
= C compiler, doesn't link C++ standard libraryg++
= C++ compiler, automatically links C++ standard library (libstdc++
)to avoid restart of VSCode, when using PowerShell in terminal, use this command to reload path
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User")
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User")
Simplify usage with Windows PowerShell commands
to simplify compile-run workflow with g++ compiler on windows,
can create a PowerShell script like this: gpp-run.ps1
# compile .c or .cpp program, run exe, and delete temp exe
# Requires g++ compiler to be installed and available in PATH
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$File,
[switch]$Keep
)
$name = [System.IO.Path]::GetFileNameWithoutExtension($File)
g++ $File -o "$name.exe"
if ($?) {
& ".\$name.exe"
if (-not $Keep) { Remove-Item "$name.exe" }
} else {
exit 1
}
then run the script with filename of .cpp of .c file, like this
> .\gpp-run.ps1 hello.cpp
or to keep result hello.exe
> .\gpp-run.ps1 hello.cpp -keep
or to for C
> .\gpp-run.ps1 hello.c
While this PowerShell script works, there is a bit more convenient option available:
to register a "function" to PowerShell, and then use this as any other command, no path required.
to register a "function" to PowerShell, and then use this as any other command, no path required.
gpp-run-function.ps1
function gpp-run($file, [switch]$keep) {
$name = [System.IO.Path]::GetFileNameWithoutExtension($file)
g++ $file -o "$name.exe"
if ($?) {
& ".\$name.exe"
if (-not $keep) {
Remove-Item "$name.exe"
}
}
}
then need to "register" this function by using "dot space" powershell command, like this
> . gpp-run-function.ps1 # the . is required
and then can just use this registered function name anywhere, like this
> gpp-run hello.cpp
> gpp-run hello.cpp -keep
> gpp-run hello.c
finally, that "register function" can be made permanent by
# Make it permanent - Add to your PowerShell profile so it's always available:
notepad $PROFILE
# Add: . "C:\path\to\your\gpp-run-function.ps1"
Using Docker containers to compiler and run C/C++
Clearly, the full installation of any of C/C++ compilers on Windows is not simple
and it also requires a lot of space, in some cases more than 10GB
and it also requires a lot of space, in some cases more than 10GB
One alternative is to use Linux in WSL2 (Windows Subsystem for Linux).
Another, even better and simpler is to Docker containers.
First, need to install Docker Desktop.
Windows | Docker Docs
Then there are already "ready to use" container images with compilers for most programming languages, including C/C++. So this is applicable to almost any other programming language compiler!
First, need to install Docker Desktop.
Windows | Docker Docs
Then there are already "ready to use" container images with compilers for most programming languages, including C/C++. So this is applicable to almost any other programming language compiler!
With single command can start Linux bash shell with g++ and gcc commands available
and with current folder and files all visible. One line!
Interactive, or better save as PowerShell script.
docker-gcc-bash.ps1
and with current folder and files all visible. One line!
Interactive, or better save as PowerShell script.
docker-gcc-bash.ps1
docker run --rm -it -v ${PWD}:/app -w /app gcc:latest bash
then, to compile, run, and delete temp exe file
$ g++ hello.c -o hello
$ ./hello
$ ./hello
$ rm hello
or, all in one line
$ g++ hello.c -o hello && ./hello &&
rm ./hello
Now, we can do even better, without even using Linux shell directly.
With this PowerShell script, it is even simpler
docker-gcc-run.ps1
With this PowerShell script, it is even simpler
docker-gcc-run.ps1
# using gcc docker container to compile .c or .cpp program, run exe, and delete temp exe
param([Parameter(Mandatory)]$File)
$cleanFile = $file -replace '^\.\\', ''
$name = [System.IO.Path]::GetFileNameWithoutExtension($cleanFile)
$ext = [System.IO.Path]::GetExtension($file)
$compiler = if ($ext -in @(".cpp", ".cxx", ".cc")) {"g++"} else {"gcc"}
docker run --rm -v "${PWD}:/app" -w /app gcc:latest sh -c "$compiler $cleanFile -o $name && ./$name && rm ./$name"
then, to compile, run, and delete temp exe file we can do with this command
> ./docker-gcc-run.ps1 hello.cpp
the same script works with .c programs, too
> ./docker-gcc-run.ps1 hello.c
to avoid need to each time enter path to PowerShell scripts,
we can register PowerShell functions.
we can register PowerShell functions.
docker-gcc-functions.ps1
# interactive terminal
function docker-gcc-bash() {
docker run --rm -it -v ${PWD}:/app -w /app gcc:latest bash
}
# compile c or cpp file to exe, run exe, delete temp exe
function docker-gcc-run($file) {
$cleanFile = $file -replace '^\.\\', ''
$name = [System.IO.Path]::GetFileNameWithoutExtension($cleanFile)
$ext = [System.IO.Path]::GetExtension($file)
$compiler = if ($ext -in @(".cpp", ".cxx", ".cc")) {"g++"} else {"gcc"}
docker run --rm -v "${PWD}:/app" -w /app gcc:latest sh -c "$compiler $cleanFile -o $name && ./$name && rm ./$name"
}
then run "register" functions, or add to $PROFILE as described above.
> . docker-gcc-run.ps1
> . docker-gcc-run.ps1
and then
> docker-gcc-run hello.cpp
or
> docker-gcc-run hello.c
Finally, we can make docker image even much smaller, by creating custom Docker image
Dockerfile
FROM alpine:latest
RUN apk add --no-cache g++ libc-dev
WORKDIR /app
then build image with command like this
docker build -t gcc-alpine .
and it all works the same, just faster and takes 5x less space, less than 250MB.
Nice improvement, 10-40x smaller than "default" solution!