fix: Add Solution in Curriculum/Challenges/English/08/CodingInterviewProblems/DataStructures/CREATE_LINKED_LIST_CLASS.md (#35819)

* fix: add solution create linked list class

* fix: added extra line to avoid linting error

* fix: renamed some variables
This commit is contained in:
Stan Choi
2019-06-20 11:11:26 -04:00
committed by Tom
parent 6fd5672753
commit 204ece1c70

View File

@ -78,6 +78,40 @@ function LinkedList() {
<section id='solution'>
```js
// solution required
function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){
this.element = element;
this.next = null;
};
this.head = function(){
return head;
};
this.size = function(){
return length;
};
this.add = function(element){
// Only change code below this line
if (head == null) {
head = new Node(element);
}
else {
let currentNode = head;
while (currentNode.next != null) {
// currentNode.next will be last node of linked list after loop
currentNode = currentNode.next;
}
currentNode.next = new Node(element);
}
length++;
// Only change code above this line
};
}
```
</section>