Computer-Wiz's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
26 (0.02 per day)
Joined:
29-January 11
Profile Views:
1,437
Last Active:
User is offline Mar 03 2013 03:37 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Computer-Wiz has not set their status

Posts I've Made

  1. In Topic: Bubble Sort Algorithm Animation

    Posted 3 Mar 2013

    Hi there, so i updated this code to organize it more but i still cant get it to do what i wanted. It still gives me the same output.

    '''
    Created on Sep 12, 2010
    
    @author: aaronkilpatrick
    '''
    from Tkinter import*
    import time
    
    
    def bubbleSort(lst):
        for number in range(len(lst)-1, 0, -1):
            for i in range(number):
                if lst[i] > lst[i + 1]:
                    lst[i], lst[i + 1] = lst[i + 1], lst[i]
                    print lst
                    for j in lst:
                        cv.delete([j])
                    animation()
                    cv.delete(ALL)
                    cv.update()
                    
                        
    def animation():
        x , y = 220, 500
        barWidth = 15
        
        
        for item in lst:
            
            cv.delete([item])
            bar = cv.create_rectangle(x, y, x+barWidth, y-(item*15), fill="red")
            x += barWidth + 5
            time.sleep(0.2)
            cv.update()
               
    #MAIN
    
    #Canvas                    
    root = Tk()
    root.title("Sorting Algorithm Animation")
    w = 800
    h = 600
    cv = Canvas(width=w, height=h, bg='black')
    
    cv.pack()
    cv.update()
    
    lst = [1,2,7,3,6,4,5,10,8,9,12,15,11,13,16,14,20,17,19,18]
    bubbleSort(lst)
    animation()
    
    root.mainloop()
    
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

Page 1 of 1
  1. Photo

    goodchild66 Icon

    21 Mar 2012 - 13:59
    hello
Page 1 of 1