Skip to content

a4amado/nero-s-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Nero Sort

Nero Sort Love at first index.

The idea is simple:

  1. Neo sees the first number in the list.
  2. Neo falls in love with it immediately.
  3. From that moment on, every number Neo sees is turned into that first number.

The process is extremely decisive.

Algorithm

Given a list:

  • If the list is empty, return the empty list.
  • Save the first value as favorite.
  • Replace every element in the list with favorite.
  • Return the modified list.

Pseudocode

NeroSort(list):
    if list is empty:
        return list

    favorite = list[0]

    for i from 0 to length(list) - 1:
        list[i] = favorite

    return list

Example

Input:

[7, 2, 9, 4, 1]

Neo sees 7, falls in love, and decides every number deserves to be 7.

Output:

[7, 7, 7, 7, 7]

Behavior

Once the first value is chosen, the rest of the list aligns with it.

Complexity

  • Time: O(n)
  • Space: O(1) if done in place

Important Note

Nero Sort produces a highly consistent final list.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors