Skip to content

Instantly share code, notes, and snippets.

@giannispan
Created February 1, 2016 17:15
Show Gist options
  • Save giannispan/4324800ea0c08be436eb to your computer and use it in GitHub Desktop.
Save giannispan/4324800ea0c08be436eb to your computer and use it in GitHub Desktop.
Linked Lists - Length & Count
function Node(data) {
this.data = data;
this.next = null;
}
function length(head) {
if (head == null)
return 0;
else
return 1 + length(head.next);
}
function count(head, data) {
if (head == null)
return 0;
var count = 0;
while (head != null)
{
if (head.data == data)
count++;
head = head.next;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment