Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scripts": {
"array": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/Array",
"linked-list": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/LinkedList",
"stack": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/Stack",
"queue": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/Queue"
},
"devDependencies": {
"@types/node": "^15.3.0",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const labenuGroups: string[] = [
"Newton",
"Bouman",
"Sagan",
"Hamilton",
"Julian",
"Melo",
"Turing",
"Jackson",
"Tang",
"Dumont"
]

const customSplice = (
array: any[],
index: number,
deleteCount: number = 1
): any => {
const elem: any[] = []
for(let i = 0; i < deleteCount; i++){
elem.push(array[index+i])
}

for(let i = index; i < array.length; i++){
array[i] = array[i+deleteCount]
}

array.length -= deleteCount;

return elem

}

const removendoItem = customSplice(labenuGroups, 2, 1)

console.log({labenuGroups, removendoItem});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class ListNode{
constructor(
public value: any,
public next: ListNode | null = null
){}
}

export const node = new ListNode("1", new ListNode("2"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//Faça a implementação de uma Lista Ligada em Typescript. Implemente o método que adiciona um elemento ao final da lista e um método que imprima todos elementos presentes nela.

import { ListNode, node } from "./ListNode";


export class List{
constructor(
public start: ListNode | null = null
){}

public addItem = (value: any): void | undefined => { //quando declaro como void obrigatóriamente quer dizer que minha função não terá um return, mas, caso a execução entre no if, precisamos que a execução se encerre, ou seja, não queremos que o código abaixo seja executado, por isso colocamos um return, pois ele encerra. Como não estmaos passando nenhum valor no return ele retorna undefined, por isso tipamos a função como undefined também, logo ela é void ou undefined.

if(!this.start){
this.start = new ListNode(value);
return //se não encerrar aqui o primeiro elemento será duplicado na execução.
}

let currentItem = this.start

while(currentItem.next){
currentItem = currentItem.next
}

currentItem.next = new ListNode(value)

}

public print() {
let node: ListNode | null = this.start;
let i = 1;
while (node) {
console.log(`Elemento ${i}: `, node.value)
node = node.next;
i++
}
return node
}

}


const list = new List()

list.addItem("one")
list.addItem("two")
list.addItem("three")
list.addItem("four")

// console.log(list)

// console.log(JSON.stringify(list, null, 2))

console.log(list.print());


Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { List } from '../LinkedList';
import { ListNode } from './../LinkedList/ListNode';
//Faça a implementação de uma Pilha em Typescript e utilizando uma Lista Ligada como estrutura de base (em aula, usamos um Array). Implemente os métodos:
///`isEmpty`: que indica se ela está vazia

//`push`: que adiciona um elemento à pilha

//`pop`: que retira um elemento da pilha

//`print`: que imprima todos os elementos da pilha


export class Stack{
constructor(
public frames: List = new List()
) {}

public isEmpty = () => this.frames.start===null

public push = (
value: any
): void => {
this.frames.addItem(value)
}

public pop = () => {
if(!this.isEmpty())return null

let previousNode: ListNode | null = null
let currentItem: ListNode | null = this.frames.start

while(currentItem!.next){
previousNode = currentItem
currentItem = currentItem!.next
}

previousNode!.next = null

return currentItem
}

public print(){
let node: ListNode | null = this.frames.start;
let i = 1;
while (node) {
console.log(`Elemento ${i}: `, node.value)
node = node.next;
i++
}
return node
}
}

const stack = new Stack()
stack.isEmpty()
stack.push("five")
stack.push("six")
console.log(stack);

console.log(stack.isEmpty());

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"outDir": "./build",
"rootDir": "./src",
"removeComments": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}