(element)
| 15 | // adds an element at the end |
| 16 | // of list |
| 17 | add(element) { |
| 18 | // creates a new node |
| 19 | var node = new Node(element); |
| 20 | |
| 21 | // to store current node |
| 22 | var current; |
| 23 | |
| 24 | // if list is Empty add the |
| 25 | // element and make it head |
| 26 | if (this.head == null) |
| 27 | this.head = node; |
| 28 | else { |
| 29 | current = this.head; |
| 30 | |
| 31 | // iterate to the end of the |
| 32 | // list |
| 33 | while (current.next) { |
| 34 | current = current.next; |
| 35 | } |
| 36 | |
| 37 | // add node |
| 38 | current.next = node; |
| 39 | } |
| 40 | this.size++; |
| 41 | } |
| 42 | |
| 43 | // insert element at the position index |
| 44 | // of the list |
no outgoing calls
no test coverage detected