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
4 changes: 4 additions & 0 deletions modulo6/Estrutura-dados/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
build
.env
13 changes: 13 additions & 0 deletions modulo6/Estrutura-dados/package.json
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"
}
}
14 changes: 14 additions & 0 deletions modulo6/Estrutura-dados/src/Array/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const labenuGroups: string[] = [
"Newton",
"Bouman",
"Sagan",
"Hamilton",
"Julian",
"Melo",
"Turing",
"Jackson",
"Tang",
"Dumont"
]

console.log(labenuGroups);
29 changes: 29 additions & 0 deletions modulo6/Estrutura-dados/src/LinkedList/LinkedList.ts
Original file line number Diff line number Diff line change
@@ -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()

}
}
}
14 changes: 14 additions & 0 deletions modulo6/Estrutura-dados/src/LinkedList/ListNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class ListNode{
constructor(
public value: any,
public next: ListNode | null = null
){}

getValue(){
return this.value
}

getNext(){
return this.next
}
}
13 changes: 13 additions & 0 deletions modulo6/Estrutura-dados/src/LinkedList/index.ts
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions modulo6/Estrutura-dados/src/Queue/Queue.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
19 changes: 19 additions & 0 deletions modulo6/Estrutura-dados/src/Queue/index.ts
Original file line number Diff line number Diff line change
@@ -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()
47 changes: 47 additions & 0 deletions modulo6/Estrutura-dados/src/Stack/LinkedList.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 14 additions & 0 deletions modulo6/Estrutura-dados/src/Stack/ListNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class ListNode{
constructor(
public value: any,
public next: ListNode | null = null
){}

getValue(){
return this.value
}

getNext(){
return this.next
}
}
26 changes: 26 additions & 0 deletions modulo6/Estrutura-dados/src/Stack/index.ts
Original file line number Diff line number Diff line change
@@ -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()

14 changes: 14 additions & 0 deletions modulo6/Estrutura-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
}
}