Created
February 1, 2016 17:15
-
-
Save giannispan/4324800ea0c08be436eb to your computer and use it in GitHub Desktop.
Linked Lists - Length & Count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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