parent
4e5d24464c
commit
907c3cad09
@ -1,6 +1,6 @@
|
||||
// In C++11 you can do the following, but most people use vector instead of arrays
|
||||
// In C++11 you can do the following, but most people use vector instead of arrays
|
||||
a.size(); // Returns the size of array a
|
||||
|
||||
int a[10]; // Declare an int array with length 10.
|
||||
int a[10]; // Declare an int array with length 10.
|
||||
a[0] = 420; // Set the value 420 to index 0 of array a
|
||||
int b = a[0] // Set variable b to 420 by accessing index 0 of array a.
|
||||
|
@ -1,20 +1,20 @@
|
||||
int main() {
|
||||
// Basic
|
||||
int main() {
|
||||
// Basic
|
||||
if(x > 0) {
|
||||
return x;
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
return -x;
|
||||
else {
|
||||
return -x;
|
||||
}
|
||||
|
||||
// if else
|
||||
if(x > 0) {
|
||||
return x;
|
||||
// if else
|
||||
if(x > 0) {
|
||||
return x;
|
||||
}
|
||||
else if(x == 0) {
|
||||
return 420;
|
||||
else if(x == 0) {
|
||||
return 420;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
return -x;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
// There are only 'for', 'while', and 'do while'
|
||||
|
||||
// For loop - Outputs "0 1 2 3 4 5 6 7 8 9"
|
||||
// For loop - Outputs "0 1 2 3 4 5 6 7 8 9"
|
||||
for( int i=0; i<10; i++ ) {
|
||||
std::cout << i << " ";
|
||||
std::cout << i << " ";
|
||||
}
|
||||
|
||||
// While loop - Outputs "0 1 2 3 4 5 6 7 8 9"
|
||||
int i = 0;
|
||||
while( i < 10 ) {
|
||||
// While loop - Outputs "0 1 2 3 4 5 6 7 8 9"
|
||||
int i = 0;
|
||||
while( i < 10 ) {
|
||||
std::cout << i << " ";
|
||||
i++;
|
||||
}
|
||||
|
||||
// While loop - Outputs "0 "
|
||||
int i = 0;
|
||||
do {
|
||||
std::cout << i << " ";
|
||||
// While loop - Outputs "0 "
|
||||
int i = 0;
|
||||
do {
|
||||
std::cout << i << " ";
|
||||
}while( i<0 );
|
||||
|
@ -1,21 +1,21 @@
|
||||
// ## Built-in Types
|
||||
bool
|
||||
// ## Built-in Types
|
||||
bool
|
||||
|
||||
char
|
||||
char
|
||||
|
||||
string
|
||||
string
|
||||
|
||||
// Assume signed, prepend unsigned to make it unsigned
|
||||
short
|
||||
short
|
||||
|
||||
int
|
||||
int
|
||||
|
||||
long
|
||||
long
|
||||
|
||||
// C++ 11
|
||||
long long
|
||||
// C++ 11
|
||||
long long
|
||||
|
||||
// Floating Points
|
||||
float
|
||||
double
|
||||
long double
|
||||
// Floating Points
|
||||
float
|
||||
double
|
||||
long double
|
||||
|
@ -1,10 +1,10 @@
|
||||
// Vectors are sequence containers representing arrays that can change in size.
|
||||
|
||||
// Library to include
|
||||
#include <vector>
|
||||
// Library to include
|
||||
#include <vector>
|
||||
|
||||
vector<int> a; // Declare an empty vector, a.
|
||||
a.push_back(1); // Appends/Adds an element whose value is 1 to vector a.
|
||||
std::cout << a.at(0) << std::endl; // Accessing index 0 of vector a.
|
||||
a.push_back(1); // Appends/Adds an element whose value is 1 to vector a.
|
||||
std::cout << a.at(0) << std::endl; // Accessing index 0 of vector a.
|
||||
a.size(); // Returns the size of the vector
|
||||
a.at(0) = 420; // Changing the value at index 0 to 420.
|
||||
a.at(0) = 420; // Changing the value at index 0 to 420.
|
||||
|
@ -1,8 +1,8 @@
|
||||
// ## Packages
|
||||
// ## Packages
|
||||
// * Package declaration at top of every source file
|
||||
// * Executables are in package `main`
|
||||
// * Convention: package name == last name of import path (import path `math/rand` => package `rand`)
|
||||
// * Upper case identifier: exported (visible from other packages)
|
||||
// * Lower case identifier: private (not visible from other packages)
|
||||
// * Lower case identifier: private (not visible from other packages)
|
||||
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
-- to install:
|
||||
-- to install:
|
||||
-- (Debian/Ubuntu) apt-get install lua
|
||||
-- (Fedora/CentOS) yum install lua
|
||||
-- (source code) curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz | tar xz -
|
||||
-- (source code) curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz | tar xz -
|
||||
-- cd lua-5.3.4
|
||||
-- make linux
|
||||
--
|
||||
-- to execute:
|
||||
-- to execute:
|
||||
-- lua hello.lua
|
||||
|
||||
io.write("Hello world, from ",_VERSION,"!\n")
|
||||
|
@ -1,15 +1,15 @@
|
||||
# For what Recursion is, please check theory/recursion
|
||||
# For what Recursion is, please check theory/recursion
|
||||
|
||||
# Simple Factorial Python Recursion
|
||||
def factorial(n) :
|
||||
if n == 0 :
|
||||
return 1
|
||||
else :
|
||||
# Simple Factorial Python Recursion
|
||||
def factorial(n) :
|
||||
if n == 0 :
|
||||
return 1
|
||||
else :
|
||||
return n * factorial(n-1)
|
||||
|
||||
# Simple Greatest Common Divisor Recursion
|
||||
def gcd(x, y) :
|
||||
if y == 0 :
|
||||
return x
|
||||
else :
|
||||
return gcd(y, x%y)
|
||||
# Simple Greatest Common Divisor Recursion
|
||||
def gcd(x, y) :
|
||||
if y == 0 :
|
||||
return x
|
||||
else :
|
||||
return gcd(y, x%y)
|
||||
|
@ -1,11 +1,11 @@
|
||||
# Recursion
|
||||
# Recursion
|
||||
# Def: "...is a method where the solution to a problem depends on solutions to smaller instance of the same problem.." - wiki
|
||||
# TL;DR: a function that calls itself inside its body.
|
||||
# TL;DR: a function that calls itself inside its body.
|
||||
|
||||
# Recursive programs - Pseduocode
|
||||
function factorial:
|
||||
# Recursive programs - Pseduocode
|
||||
function factorial:
|
||||
input: integer n such that n >= 0
|
||||
output: n * (n-1) * (n-2) * ... * 1 = n!
|
||||
|
||||
1. if n is 0, return 1
|
||||
1. if n is 0, return 1
|
||||
2. else, return ( n * factorial(n-1) )
|
||||
|
@ -1,15 +1,15 @@
|
||||
# C++
|
||||
#
|
||||
#
|
||||
# C++ is an object-oriented programming language which provides facilities for low-level memory manipulation.
|
||||
# It is widely used by big tech companies, such as, Amazon, Facebook, Google, and SpaceX
|
||||
#
|
||||
# To Compile: g++ my_script.cpp
|
||||
# To Execute: ./a.out
|
||||
#
|
||||
# See also
|
||||
# See also
|
||||
# C++ language cheat sheet at /c++/
|
||||
# list of pages: /c++/:list
|
||||
# learn C++: /c++/:learn
|
||||
# C++ one-liners: /c++/:1line
|
||||
# C++ weirdness: /c++/weirdness
|
||||
# C++ weirdness: /c++/weirdness
|
||||
# search in pages: /c++/~keyword
|
||||
|
@ -1,12 +1,12 @@
|
||||
# ranlib
|
||||
#
|
||||
# generates an index to the contents of an archive and stores it in the archive.
|
||||
# The index lists each symbol defined by a member of an archive that is a relocatable object file.
|
||||
# The index lists each symbol defined by a member of an archive that is a relocatable object file.
|
||||
|
||||
# This creates an index of the contents of fruits.a and stores the index in fruits.a
|
||||
# This is useful for linking and in case the objects call each other.
|
||||
ranlib fruits.a
|
||||
# after
|
||||
# after
|
||||
# ar r fruits.a apple.o orange.o pineapple.o
|
||||
# is called
|
||||
|
||||
|
Loading…
Reference in New Issue