Eventually I came to the conclusion that my algorithm was not going to work, so I had to start from scratch. I ended up wiki-ing sorting methods, and tried implementing the first one: a bubble sort. Finally, I just ended up borrowing code from dreamincode.net. Here's my final product for a bubble sorter:
Now the better thing for me to do here is explain what's happening. After you provide your list, it goes through the array two at a time next to each other (hence the i and the j) to see if they are backwards (-1). If they are, it fixes them. It keeps going through the list until it doesn't return a "backwards," the returns the new sorted list. I added a clear method after the return so you can just start a new list again.
In order to get more comfortable with all this, I'd like to check out a few more sort methods and use my cards that I made to go through each one manually so I can understand them better. Apparently bubble sort is incredibly slow and not good for larger patterns.
Last night I almost finished the shuffle algorithm, but I think I'm also going to see if I can find some on the internet already, and then play around with those. I'd like to think you could just use bubble sort with rand and just repeat that 100 times or so.
Back to house kinds of things. I need to start packing for my cross country trip, and this place is a mess.
No comments:
Post a Comment