My attempt at creating double linked list with methods similar to Array like push, pop etc. ,implementing some basic sorting algorithms on created list and testing it with jest.
- unshift(newHead): adds "newHead" node to the beginning of the list.
- shift(): removes first node from the list, returns removed node.
- push(newTail): adds "newTail" node to the end of the list.
- pop(): removes last node from the list, returns removed node.
- log(): returns a string with all nodes in a list.
- findByIndex(searched): search through the list to find node with a given index, returns node with a given index.
- indexOf(data): search through the list to find all Nodes with a given data, returns array with indexes of finded nodes.
- isEmpty(): checks if a list is empty, returns true if is empty else false.
- swap(x, y): swaps places of two given nodes.
- isPartOfTheList(toCheck): checks if given node is part of the list, returns true if is part of the list else false.
- forEach(func): takes function and executes it once for each list element. func(current, index) is called with two arguments current which is current node, index is index of current node in list.
- remove(toRemove): removes given node from the list, returns removed node.
- insertBefore(toInsert, next): takes two nodes toInsert node to insert to list, next node before which toInsert will be inserted.
- insertAfter(toInsert, next): takes two nodes toInsert node to insert to list, previous node after which toInsert will be inserted.
- bubbleSort
- cocktailShakerSort
- quickSort/quickSortMiddle first one uses last element as pivot second middle one.
- heapSort
- insertionSort
- mergeSort
- selectionSort
Clone the project
git clone https://github.com/SaberLS/double-linked-list.git
Go to the project directory
cd double-linked-list
Install dependencies
yarn install
To run tests, run the following command
yarn test
it runs all the tests and creates test coverage report at ./jest_html_reporters.html with use of jest-html-reporters