Add LinkedList.

This commit is contained in:
Oleksii Trekhleb 2018-03-27 15:20:46 +03:00
parent 909976c7bf
commit 53ca279c3b
3 changed files with 8 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import Node from './Node';
import LinkedListNode from './LinkedListNode';
export default class LinkedList {
constructor() {
@ -6,7 +6,7 @@ export default class LinkedList {
}
append(value) {
const newNode = new Node(value);
const newNode = new LinkedListNode(value);
// If there is no head yet let's make new node a head.
if (!this.head) {
@ -28,8 +28,8 @@ export default class LinkedList {
}
prepend(value) {
const newNode = new Node(value);
this.head = new Node(value, this.head);
const newNode = new LinkedListNode(value, this.head);
this.head = newNode;
return newNode;
}

View File

@ -1,4 +1,4 @@
export default class Node {
export default class LinkedListNode {
constructor(value, next = null) {
this.value = value;
this.next = next;

View File

@ -1,8 +1,8 @@
import Node from '../Node';
import LinkedListNode from '../LinkedListNode';
describe('Node', () => {
describe('LinkedListNode', () => {
it('should create list node with value', () => {
const node = new Node(1);
const node = new LinkedListNode(1);
expect(node.value).toBe(1);
expect(node.next).toBeNull();
});