Merge branch 'main' into csci

This commit is contained in:
Mike 2024-02-01 19:44:34 -05:00 committed by GitHub
commit ddba85e74b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

1
.gitignore vendored
View file

@ -129,3 +129,4 @@ dist
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
.DS_STORE

View file

@ -5,16 +5,6 @@ class LinkedList {
this.head = null; this.head = null;
} }
getHead() {
return this.tail;
}
getTail() {
return this.head;
}
getSize() {
return this.size;
}
append(value) { append(value) {
let newNode = new Node(value); let newNode = new Node(value);
@ -27,6 +17,7 @@ class LinkedList {
} }
if (this.tail == null) { if (this.tail == null) {
this.tail = newNode; this.tail = newNode;
} }
this.size += 1; this.size += 1;
@ -34,6 +25,7 @@ class LinkedList {
prepend(value) { prepend(value) {
let newNode = new Node(value); let newNode = new Node(value);
if (this.tail == null) { if (this.tail == null) {
this.tail = newNode; this.tail = newNode;
if (this.head == null) { if (this.head == null) {
@ -43,6 +35,7 @@ class LinkedList {
const temp = this.tail; const temp = this.tail;
temp.nextNode = newNode; temp.nextNode = newNode;
this.tail = newNode; this.tail = newNode;
} }
this.size += 1; this.size += 1;
} }
@ -66,6 +59,7 @@ class LinkedList {
this.tail = null; this.tail = null;
} else { } else {
this.head = this.head.nextNode; this.head = this.head.nextNode;
} }
this.size -= 1; this.size -= 1;
} }
@ -82,6 +76,7 @@ class LinkedList {
} }
return searchNodes(this.head, value); return searchNodes(this.head, value);
} }
find(value) { find(value) {
@ -97,12 +92,14 @@ class LinkedList {
} }
return searchNodes(this.head, value, index); return searchNodes(this.head, value, index);
} }
insertAt(value, index) { insertAt(value, index) {
let previousNode = null; let previousNode = null;
let newNode = new Node(value); let newNode = new Node(value);
let currentNode = this.head; let currentNode = this.head;
let count = 0; let count = 0;
if (index === 0) { if (index === 0) {
@ -132,6 +129,7 @@ class LinkedList {
removeAt(index) { removeAt(index) {
let previousNode = null; let previousNode = null;
let currentNode = this.head; let currentNode = this.head;
let count = 0; let count = 0;
if (index === 0) { if (index === 0) {
@ -160,6 +158,7 @@ class LinkedList {
let nodes = []; let nodes = [];
let current = this.head; let current = this.head;
while (current != null) { while (current != null) {
nodes.push(current.value); nodes.push(current.value);
current = current.nextNode; current = current.nextNode;
@ -212,4 +211,5 @@ list.removeAt(0);
list.toString(); list.toString();
console.log("Removing element Deez Nuts"); console.log("Removing element Deez Nuts");
list.removeAt(3); list.removeAt(3);
list.toString(); list.toString();