Code Monkey home page Code Monkey logo

Comments (4)

ramanan12345 avatar ramanan12345 commented on May 16, 2024

Python program to implement Pigeonhole Sort */

source code : "https://en.wikibooks.org/wiki/

Algorithm_Implementation/Sorting/Pigeonhole_sort"

def pigeonhole_sort(a):
# size of range of values in the list
# (ie, number of pigeonholes we need)
my_min = min(a)
my_max = max(a)
size = my_max - my_min + 1

# our list of pigeonholes
holes = [0] * size

# Populate the pigeonholes.
for x in a:
    assert type(x) is int, "integers only please"
    holes[x - my_min] += 1

# Put the elements back into the array in order.
i = 0
for count in range(size):
    while holes[count] > 0:
        holes[count] -= 1
        a[i] = count + my_min
        i += 1

a = [8, 3, 2, 7, 4, 6, 8]
print("Sorted order is : ", end = ' ')

pigeonhole_sort(a)

for i in range(0, len(a)):
print(a[i], end = ' ')

from al-go-rithms.

ramanan12345 avatar ramanan12345 commented on May 16, 2024

this alogrithm

from al-go-rithms.

ZoranPandovski avatar ZoranPandovski commented on May 16, 2024

@ramanan12345 Sure go ahead, add that algorithm following the contribution guide. Thanks

from al-go-rithms.

namish800 avatar namish800 commented on May 16, 2024

@ZoranPandovski review PR #186

from al-go-rithms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.