Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ativos = [0, 6, 13, 4]
- const arquivos = ['anotacao.txt', 'mus1.mp3', 'relatorio.pdf', 'index.js'];
- const inicio = {
- responsabilidade: null,
- prox: null,
- anterior: null,
- id: 0,
- ativo: ativos.includes(0),
- arquivos: []
- }
- const fim = {
- responsabilidade: null,
- prox: null,
- anterior: null,
- id: 16,
- ativo: ativos.includes(16),
- arquivos: []
- }
- inicio.anterior = fim;
- fim.prox = inicio;
- const quantidade = 16
- function gerarListaCircular() {
- let pos = 0;
- let atual = inicio;
- for(;;) {
- if (pos > 16) break;
- if (pos === 0) {
- atual.prox = {
- responsabilidade: null,
- prox: null,
- anterior: inicio,
- id: pos+1,
- ativo: ativos.includes(pos+1),
- arquivos: []
- }
- }
- if (pos !== 16 && pos !== 0) {
- if (pos === 15) {
- atual.prox = fim;
- fim.anterior = atual
- } else {
- atual.prox = {
- responsabilidade: null,
- prox: null,
- anterior: atual,
- id: pos+1,
- ativo: ativos.includes(pos+1),
- arquivos: []
- }
- }
- }
- atual = atual.prox;
- pos++;
- }
- }
- function printarLista () {
- let pos = 0;
- let atual = inicio;
- for(;;) {
- if (pos > 16) break;
- // if (pos === 16) {
- // console.log(atual)
- // }
- console.log('\nAnterior: ', atual.anterior.id)
- console.log('Node: ', atual.id)
- console.log('Prox: ', atual.prox.id)
- console.log('Ativo: ', atual.ativo)
- console.log('Responsabilidade: ', atual.responsabilidade)
- pos++;
- atual = atual.prox;
- }
- }
- function setResponsabilidade () {
- let pos = 0;
- let atual = inicio;
- for(;;) {
- if (pos > 16) break;
- if (atual.ativo) {
- let auxAtivo = atual;
- do {
- auxAtivo = auxAtivo.anterior;
- if (auxAtivo.ativo) {
- atual.responsabilidade = auxAtivo.id;
- }
- } while (!auxAtivo.ativo)
- }
- pos++;
- atual = atual.prox;
- }
- }
- function hashFunction (string) {
- return (string.charCodeAt(0) + string.charCodeAt(1) + string.charCodeAt(2)) % 16;
- }
- function distribuirArquivos() {
- for (const arquivo of arquivos) {
- const lugarParaColcarArq = hashFunction(arquivo);
- console.log('lugarParaColcarArq', lugarParaColcarArq);
- }
- }
- gerarListaCircular();
- // setResponsabilidade();
- printarLista();
- // console.log(hashFunction('Rafael'))
- // let atual = inicio;
- // for(;;) {
- // console.log(atual)
- // atual = atual.prox
- // }
- // console.log(inicio)
Advertisement
Add Comment
Please, Sign In to add comment