# \[SOLVED\]\[not swapping\]Need help with Comb Sort visualzation

**URL:** <https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894>\
**Category:** Processing.py\
**Created:** [April 2, 2019, 9:27pm UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894 "2019-04-02T21:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [April 2, 2019, 9:27pm UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894/1 "2019-04-02T21:27:02Z")

</div>

```auto
from SkyScrapperClasSS import Sky

width = 1000
height = width/2
num = 100
heights = []
counter = 0
gap = num*10/13
swapped = False
caounter = 0
getg = False
r = color(255,0,0)

def setup():
    size(width,height)
    for i in range(num):
        heights.append(Sky(i*10,random (height)))

def draw():
    global gap,getg,counter,swapped
    print(gap)
    background(0)
    swapped = False
    
    if getg:
        gap = gapper(gap)

    for i in range(num):
        if getg:
            getg = False
        if counter >= num - gap and not getg:
            getg = True
        if counter == i or counter == i + gap:
            text(heights[i].x/10,heights[i].x,10)
            fill(255,0,0)
        else:
            fill(255)
        heights[i].show()
        if not(counter >= num - gap):
            if heights[counter].y > heights[counter + gap].y:
                swapped = True
                print("swappin")
                heights[counter].x, heights[counter + gap].x = heights[counter + gap].x, heights[counter].x

    counter += 1
    if not swapped and gap == 1:
        print("Printin :")
        for i in range(num):
            print(heights[i].x,heights[i].y)
        noLoop()

        
        
def gapper(gap):
    gap = int((gap*10) / 13)
    if gap < 1:
        return 1
    return gap

```

```auto
class Sky:
    def __init__ (self,x,y):
        self.x = x
        self.y = y

    def show(self):
        rect(self.x,height-self.y,10,self.y)
        

```

(I know that this code is a mess, a class is too much i could’ve used an array of pvectors and other stuff)The point is, i am swapping the X coordinate of a rect if his height is higer,and when i print theyr X, i can see the X actually swapped, but on the screen nothing changes

☹

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [April 2, 2019, 10:49pm UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894/2 "2019-04-02T22:49:15Z")

</div>

Remove your call to `noLoop()` at the end of `draw()`. Do you still have the same problem?

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [April 3, 2019, 5:46am UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894/3 "2019-04-03T05:46:22Z")

</div>

Yeap, I still have this problem

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 5, 2019, 8:00pm UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894/4 "2019-04-05T20:00:45Z")

</div>

Here is a guess. Set your initial gap to 1. That should make your comb sort perform its final (bubble sort) pass, correct?

What happens instead? Why?

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [April 5, 2019, 9:07pm UTC](https://discourse.processing.org/t/solved-not-swapping-need-help-with-comb-sort-visualzation/9894/5 "2019-04-05T21:07:25Z")

</div>

I’ve read again my code now, and I’ve just seen that the problem was that I wasnt converting to int() everytime I was recalculating the gap 🤪
