Coder Social home page Coder Social logo

hritesh1001 / sorting-algorithm-visualizer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 25.63 MB

A Sorting Visualizer using Python, PyGame and PyInstaller. Sorting Algorithms : Insertion Sort, Bubble Sort, Merge Sort, Quick Sort, Selection Sort

Python 100.00%
pygame pyinstaller python sorting-visualization

sorting-algorithm-visualizer's Introduction

  • Hi๐Ÿ‘‹, I am Hritesh Bhardwaj
  • I am Computer Science & Engineering Pre-Final Year Student at KIIT University๐Ÿ‘จโ€๐ŸŽ“.
  • I am highly interested in DSA and CP๐Ÿ‘จโ€๐Ÿ’ป.
  • Adding Coffeeโ˜• to my Code.
  • ๐Ÿ“œ My Resume

sorting-algorithm-visualizer's People

Contributors

hritesh1001 avatar

Stargazers

 avatar

Watchers

 avatar

sorting-algorithm-visualizer's Issues

Insertion sort code error

The function used for insertion sort has an error because of which the visualizer keeps swapping elements like bubble sort.

Problem in code

        while True:
            ascending_sort = i > 0 and lst[i - 1] > cur and ascending
            descending_sort = i > 0 and lst[i - 1] < cur and not ascending
            if not ascending_sort and not descending_sort:
                break
            lst[i] = lst[i - 1]
            i = i - 1
            #lst[I] = cur keeps swapping the adjacent elements
            lst[i] = cur
            draw_lst(draw_info, {i: draw_info.RED, i - 1: draw_info.GREEN}, True)
            yield True

The above code snippet is present in the code base. It should be replaced by last[I] = cur after the while loop when the cur is at the position it should be inserted at.

Rectified code

def insertion_sort(draw_info, ascending=True):
    lst = draw_info.lst
    for i in range(1, len(lst)):
        cur = lst[i]
        while True:
            ascending_sort = i > 0 and lst[i - 1] > cur and ascending
            descending_sort = i > 0 and lst[i - 1] < cur and not ascending
            if not ascending_sort and not descending_sort:
                break
            lst[i] = lst[i - 1]
            i = i - 1
            draw_lst(draw_info, {i: draw_info.RED, i - 1: draw_info.GREEN}, True)
            yield True
        lst[i] = cur

    return lst

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.