diff --git a/modulo6/Estrutura-dados/.gitignore b/modulo6/Estrutura-dados/.gitignore new file mode 100644 index 0000000..8ece3ba --- /dev/null +++ b/modulo6/Estrutura-dados/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/modulo6/Estrutura-dados/package.json b/modulo6/Estrutura-dados/package.json new file mode 100644 index 0000000..31c7104 --- /dev/null +++ b/modulo6/Estrutura-dados/package.json @@ -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" + } +} diff --git a/modulo6/Estrutura-dados/src/Array/index.ts b/modulo6/Estrutura-dados/src/Array/index.ts new file mode 100644 index 0000000..8831b9f --- /dev/null +++ b/modulo6/Estrutura-dados/src/Array/index.ts @@ -0,0 +1,14 @@ +const labenuGroups: string[] = [ + "Newton", + "Bouman", + "Sagan", + "Hamilton", + "Julian", + "Melo", + "Turing", + "Jackson", + "Tang", + "Dumont" +] + +console.log(labenuGroups); \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/LinkedList/LinkedList.ts b/modulo6/Estrutura-dados/src/LinkedList/LinkedList.ts new file mode 100644 index 0000000..888632b --- /dev/null +++ b/modulo6/Estrutura-dados/src/LinkedList/LinkedList.ts @@ -0,0 +1,29 @@ +import { ListNode } from "./ListNode"; + +export class LinkedList{ + constructor( + public start: ListNode | null = null + ){} + + public addToTail(value: any){ + if(!this.start){ + this.start = new ListNode(value) + return + } + let node = this.start + while (node.next !== null){ + node = node.next + } + node.next = new ListNode(value) + } + + public printList(){ + let node = this.start + + while (node !== null){ + console.log(node.getValue()) + node = node.getNext() + + } + } +} \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/LinkedList/ListNode.ts b/modulo6/Estrutura-dados/src/LinkedList/ListNode.ts new file mode 100644 index 0000000..c8aa6f3 --- /dev/null +++ b/modulo6/Estrutura-dados/src/LinkedList/ListNode.ts @@ -0,0 +1,14 @@ +export class ListNode{ + constructor( + public value: any, + public next: ListNode | null = null + ){} + + getValue(){ + return this.value + } + + getNext(){ + return this.next + } +} \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/LinkedList/index.ts b/modulo6/Estrutura-dados/src/LinkedList/index.ts new file mode 100644 index 0000000..be1c525 --- /dev/null +++ b/modulo6/Estrutura-dados/src/LinkedList/index.ts @@ -0,0 +1,13 @@ +import { LinkedList } from "./LinkedList"; +import { ListNode } from "./ListNode"; + +const primeiro: ListNode = new ListNode("primeiro") +const lista: LinkedList = new LinkedList(primeiro) + +lista.addToTail("segundo") +lista.addToTail("terceiro") +lista.addToTail("quarto") + +// console.log(lista) + +lista.printList() diff --git a/modulo6/Estrutura-dados/src/Queue/Queue.ts b/modulo6/Estrutura-dados/src/Queue/Queue.ts new file mode 100644 index 0000000..7591db7 --- /dev/null +++ b/modulo6/Estrutura-dados/src/Queue/Queue.ts @@ -0,0 +1,26 @@ +import { ListNode } from "../LinkedList/ListNode" + +export class Queue{ + constructor( + public items: any[] = [] + ){} + public isEmpty(): boolean{ + return this.items.length === 0 + } + + public enqueue(value: any): void{ + this.items[this.items.length] = value + } + + public dequeue(): any{ + const firstItem = this.items[0] + + this.items.splice(0, 1) + + return firstItem + } + + public printQueue(): void{ + console.log(this.items) + } +} \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/Queue/index.ts b/modulo6/Estrutura-dados/src/Queue/index.ts new file mode 100644 index 0000000..9ea882e --- /dev/null +++ b/modulo6/Estrutura-dados/src/Queue/index.ts @@ -0,0 +1,19 @@ +import { Queue } from "./Queue" + +const array: any[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +const queueArray = new Queue(array) + +// isEmpty +console.log(queueArray.isEmpty()) + +// enqueue +queueArray.enqueue(11) +queueArray.printQueue() + +// dequeue +queueArray.dequeue() +queueArray.printQueue() + +// print +queueArray.printQueue() \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/Stack/LinkedList.ts b/modulo6/Estrutura-dados/src/Stack/LinkedList.ts new file mode 100644 index 0000000..069882d --- /dev/null +++ b/modulo6/Estrutura-dados/src/Stack/LinkedList.ts @@ -0,0 +1,47 @@ +import { ListNode } from "./ListNode"; + +export class LinkedList { + constructor( + public start: ListNode | null = null + ) { } + + public isEmpty(): boolean { + return this.start === null + } + + public push(value: any) { + if (!this.start) { + this.start = new ListNode(value) + return + } + let node = this.start + while (node.next !== null) { + node = node.next + } + node.next = new ListNode(value) + } + + public printList() { + let node = this.start + + while (node !== null) { + console.log(node.getValue()) + node = node.getNext() + + } + } + + public pop() { + let previousNode: ListNode | null = null + let currentNode: ListNode | null = this.start + + while(currentNode!.next !== null){ + previousNode = currentNode + currentNode = currentNode!.next + } + + previousNode!.next = null + + return currentNode + } +} \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/Stack/ListNode.ts b/modulo6/Estrutura-dados/src/Stack/ListNode.ts new file mode 100644 index 0000000..c8aa6f3 --- /dev/null +++ b/modulo6/Estrutura-dados/src/Stack/ListNode.ts @@ -0,0 +1,14 @@ +export class ListNode{ + constructor( + public value: any, + public next: ListNode | null = null + ){} + + getValue(){ + return this.value + } + + getNext(){ + return this.next + } +} \ No newline at end of file diff --git a/modulo6/Estrutura-dados/src/Stack/index.ts b/modulo6/Estrutura-dados/src/Stack/index.ts new file mode 100644 index 0000000..3f54b49 --- /dev/null +++ b/modulo6/Estrutura-dados/src/Stack/index.ts @@ -0,0 +1,26 @@ +import { LinkedList } from "./LinkedList"; +import { ListNode } from "./ListNode"; + +const primeiro: ListNode = new ListNode("primeiro") +const lista: LinkedList = new LinkedList() + + + +//isEmpty + +console.log(lista.isEmpty()) + +// push +const lista2: LinkedList = new LinkedList(primeiro) +lista2.push("segundo") +lista2.push("terceiro") +lista2.push("quarto") +lista2.printList() + +//pop +lista2.pop() +lista2.printList() + +//print +lista2.printList() + diff --git a/modulo6/Estrutura-dados/tsconfig.json b/modulo6/Estrutura-dados/tsconfig.json new file mode 100644 index 0000000..f9701d4 --- /dev/null +++ b/modulo6/Estrutura-dados/tsconfig.json @@ -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 + } +} \ No newline at end of file