Skip to content

Instantly share code, notes, and snippets.

@szinck1
Created February 21, 2021 19:06
Show Gist options
  • Save szinck1/74c85945510be26e85caeb4c19f90599 to your computer and use it in GitHub Desktop.
Save szinck1/74c85945510be26e85caeb4c19f90599 to your computer and use it in GitHub Desktop.
class ListNode {
constructor(data) {
this.data = data
this.next = null
}
}
class LinkedList {
constructor(head = null) {
this.head = head
}
}
let node1 = new ListNode(2)
let node2 = new ListNode(5)
node1.next = node2
var list = new LinkedList(node1)
function searchLL(list, item) {
var temp = list.head;
while (temp !== null) {
if(temp.data === item) {
return true;
}
temp = temp.next;
}
return false
}
searchLL(list, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment