Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array sort #167

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
prepend-linked-list
  • Loading branch information
name committed Nov 2, 2022
commit c629ced6ddba4f8a424831d9f6d62ccf3f24da2f
29 changes: 29 additions & 0 deletions linked list/prepend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Add

What we will do first is add a value to a Linked List.

```js
class Node {
constructor(data) {
this.data = data
this.next = null
}
}

class LinkedList {
constructor(head) {
this.head = head
}

prepend = (value) => {
const newNode = new Node(value)

if (!this.head) {
this.head = newNode
}
else {
newNode.next = this.head
this.head = newNode
}
}
}