项目作者: kanow-algorithms

项目描述 :
Insertion sort implementation with explanation
高级语言: TypeScript
项目地址: git://github.com/kanow-algorithms/insertion-sort.git
创建时间: 2019-11-26T15:04:57Z
项目社区:https://github.com/kanow-algorithms/insertion-sort

开源协议:

下载


insertion-sort

Instalation

After you clone this repo you need to move inside insertion-sort directory and run command

npm install

To run npm install you must have installed node.js

Description

Example input :

  1. const testArray: number = [2, 5, -12, 91, 5];
  2. insertionSort(testArray, SortDirection.DESC);

Output of example input :

  1. [-12, 2, 5, 5, 91]

insertionSort method takes two parametrs:

  • elementsList -> it is the list which you want to sort
  • direction -> it is optional parameter which you can set as ASC or DESC (ASC is default option)

    ASC (Ascending), DESC Descending)

How it works

On this graphic you can see how insertion-sort algortihm works :


InsertionSort