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
14 changes: 14 additions & 0 deletions modulo8/Estrutura-de-dados/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"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"
}
}

50 changes: 50 additions & 0 deletions modulo8/Estrutura-de-dados/src/Array/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const labenuGroups: string[] = [
"Newton",
"Bouman",
"Sagan",
"Hamilton",
"Julian",
"Melo",
"Turing",
"Jackson",
"Tang",
"Dumont "
]


// const matriz = [
// [1,0],
// [0,1],
// [0,0]
// ]

// for(let linha of matriz){
// for(let coluna of linha){
// // lógica
// }
// }


const customSplice = (
array: any[],
index: number,
deleteCount: number = 1
): any => {
const removedItems = []

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

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

array.length -= deleteCount

return removedItems
}

const item = customSplice(labenuGroups, 1, 3)

// console.log({ labenuGroups, item });
10 changes: 10 additions & 0 deletions modulo8/Estrutura-de-dados/src/LinkedList/ListNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class ListNode {
constructor(
public value: any,
public next: ListNode | null = null
) { }


}

export const node = new ListNode("segunda", new ListNode("terça"))
49 changes: 49 additions & 0 deletions modulo8/Estrutura-de-dados/src/LinkedList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ListNode, node } from "./ListNode";

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

public addToTail = (
value: any
): void | undefined => {

if (!this.start) {
this.start = new ListNode(value)
return
}

let currentNode = this.start

while (currentNode.next !== null) {
currentNode = currentNode.next
}

currentNode.next = new ListNode(value)

}

public find = (
value: any
): ListNode | null => {

let currentNode = this.start

while(
currentNode !== null &&
currentNode.value !== value
){
currentNode = currentNode.next
}

return currentNode
}
}

const list = new LinkedList()

list.addToTail("segunda")
list.addToTail("terça")
list.addToTail("quarta")
list.addToTail("quinta")
35 changes: 35 additions & 0 deletions modulo8/Estrutura-de-dados/src/Queue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LinkedList } from "../LinkedList";
import { ListNode } from "../LinkedList/ListNode";

export class Queue {
constructor(
public items: LinkedList = new LinkedList()
) { }

public isEmpty = (): boolean => this.items.start === null

public enqueue = (
value: any
): void => {
this.items.addToTail(value)
}

public dequeue = (): ListNode | null => {

if (this.items.start === null) return null

const removedItem = { ...this.items.start }

this.items.start = this.items.start.next

return removedItem
}
}

const requests = new Queue()

requests.enqueue("request 1")
requests.enqueue("request 2")
requests.enqueue("request 3")

const request = requests.dequeue()
33 changes: 33 additions & 0 deletions modulo8/Estrutura-de-dados/src/Stack/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export class Stack {
constructor(
public frames: any[] = []
) { }

public isEmpty = () => this.frames.length === 0

public push = (
value: any
): void => {

const index = this.frames.length

this.frames[index] = value
}

public pop = ():any=>{

const index = this.frames.length - 1

const removedItem = this.frames[index]

this.frames.length--

return removedItem
}
}

const stack = new Stack()

stack.push("segunda")
stack.push("terça")
stack.push("quarta")
14 changes: 14 additions & 0 deletions modulo8/Estrutura-de-dados/tsconfig.json
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
}
}