This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'..."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function criadorDeClosure(param){ | |
var aux = 0; | |
return function(){ | |
aux++; | |
console.log("aux: %s - param: %s", aux, param); | |
}; | |
} | |
var closure1 = criadorDeClosure(1); | |
closure1(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |