Skip to content

Instantly share code, notes, and snippets.

View renatoargh's full-sized avatar

Renato Gama renatoargh

View GitHub Profile
function escopo(parametro){
var auxiliar = parametro + 2;
function interna1(){
console.log("auxiliar: %s - parâmetro: %s", auxiliar, parametro);
//Acesso a atributos internos de escopo()
}
function interna2(){
console.log("Invocando a função 'interna1'...");
function criadorDeClosure(param){
var aux = 0;
return function(){
aux++;
console.log("aux: %s - param: %s", aux, param);
};
}
var closure1 = criadorDeClosure(1);
closure1();
@renatoargh
renatoargh / Bubblesort.js
Created July 17, 2012 20:30
Bubblesort Implementation in Java Script
function swap(array, i, j){
var aux = array[i];
array[i] = array[j];
array[j] = aux;
}
function bubbleSort(array, ascending){
for(i = 0; i < array.length; i++){
for(j = array.length - 1; j >= i + 1; j--){
if((array[j] < array[j - 1]) === ascending){
function somatorio(inicio, final, funcao){
if(!funcao)
funcao = function(i) { return i; };
var acumulador = 0;
for(i = inicio; i <= final; i++){
acumulador += funcao(i, acumulador);
}
return acumulador;
function merge(array, lower, half, upper){
var left = [], i = 0;
while (i < half - lower + 1){
left.push(array[lower + i++]);
}
left.push(Number.MAX_VALUE);
var right = [], j = 0;
while(j < upper - half){
right.push(array[half + j++ + 1]);
function merge(array, lower, half, upper){
var left = [], i = 0;
while (i < half - lower + 1){
left.push(array[lower + i++]);
}
left.push(Number.MAX_VALUE);
var right = [], j = 0;
while(j < upper - half){
right.push(array[half + j++ + 1]);
function insertionSort(array, ascending){
if(ascending === undefined)
ascending = true;
for(i = 1; i < array.length; i++){
var key = array[i];
var j = i - 1;
while(j >= 0 && (array[j] > key === ascending)){
array[j + 1] = array[j];
function mergeSort(array, lower, upper){
if(lower < upper){
var half = Math.floor((lower + upper)/2);
mergeSort(array, lower, half);
mergeSort(array, half + 1, upper);
merge(array, lower, half, upper);
}
}
int y = 1; //y esta armazenada no seção `globals`
int main(){
int x = 4;//x esta armazenada na seção `stack`
printf("x está armazenada em %p", &x);
//x está armazenada em 0x7fff69032c24
return 0;
}
void alterarValor(int x){
x = x + 2;
}
int main(){
int x = 4;//x esta armazenada na seção `stack`
printf("x está armazenada em %p \n\n", &x);
//x está armazenada em 0x7fff69032c24
printf("Valor inicial de x: %i", x);