Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: BUBBLE SORT

Started 1 month, 2 weeks ago by PAguilar09
Hey guys okay so im trying to do a Bubble Sort dealing with an array of data that is being loaded at form load from a text file But right now i keep getting an error everytime it is being executed. I keep getting this error: Index was outside the bounds of the array! But i cant see where I am gng wrong? This is what i am trying to do: my array contains values like this: "C2 H2 SA D4 D2 DA SK ...
Site: CodeProject: Discussion Boards. Free source code and programming help  CodeProject: Discussion Boards. Free source code and programming help - site profile
Forum: Visual Basic / VB.NET  Visual Basic / VB.NET - forum profile
Total authors: 6 authors
Total thread posts: 11 posts
Thread activity: no new posts during last week
Domain info for: codeproject.com

Other posts in this thread:

Christian Graus replied 1 month, 2 weeks ago
PAguilar09 wrote: If ShuffleCards.cards2(i) > ShuffleCards.cards2(i + 1) Then If i counts up to the biggest possible value, when it gets there, is i+1 still inside the array, or not ?

PAguilar09 replied 1 month, 2 weeks ago
well i set breakpoints and saw that as the loop runs my arraylength is 51 since the index value = 51 because there are 52 values total During the loop i also saw that the values are not being sorted in ascending order it takes the first value in teh array and tests to see if its in order if not then it should swap. I am so lost at why this sort wont work??????

Christian Graus replied 1 month, 2 weeks ago
I'm not sure how I can make it clearer. Look at the error message again, then consider if you have 52 items, numbered 0 to 51, and your loop value is 51, and you look for the index at i+1, what will happen.

nlarson11 replied 1 month, 2 weeks ago
if your going to use a do and a for - then you need to make sure your not exceeding the size of the array. You can't compare if i+1 is greater then getupperbound(0). so you need to test for that. if you use a for and a for then it will do it for you. Dim sa() As String = { " a" , " z" , " e" , " b" , " j" , " k" , " o" , " c" , " d" , " r" , " n" , " i" , " ...

_Damian S_ replied 1 month, 2 weeks ago
So if I am looking at item 51... (because it's a 0 based array, therefore 52 items are indexed 0 to 51), you are saying that if I attempt to look at item 51 + 1 = 52, this might be out of bounds on an array of items indexed 0 to 51?

Christian Graus replied 1 month, 2 weeks ago
Wait - there's a thought !!!

_Damian S_ replied 1 month, 2 weeks ago
If ever there was a first year programming homework question, it's a bubblesort implementation!!

Christian Graus replied 1 month, 2 weeks ago
Yep, and that's precisely why I was trying to lead him to water, rather than provide a direct answer.

Mycroft Holmes replied 1 month, 2 weeks ago
I hope your tongue gets stuck firmly in your cheek ;P.

The Man from U.N.C.L.E. replied 1 month, 2 weeks ago
I remember developing a wonderful bit of code for a bubblesort algorithm. Imagine how gutted I was when I discovered that by writing a simple IComparer implementation I could take advantage of the much better bubblesort algorithim built in to .Net. Just like Microsoft to develop the same code already. Serves me right for not checking the documentation first.

 

Top contributing authors

Name
Posts
Christian Graus
4
user's latest post:
BUBBLE SORT
Published (2009-11-09 23:29:00)
Yep, and that's precisely why I was trying to lead him to water, rather than provide a direct answer.
PAguilar09
2
user's latest post:
BUBBLE SORT
Published (2009-11-09 22:46:00)
well i set breakpoints and saw that as the loop runs my arraylength is 51 since the index value = 51 because there are 52 values total During the loop i also saw that the values are not being sorted in ascending order it takes the first value in teh array and tests to see if its in order if not then it should swap. I am so lost at why this sort wont work??????
_Damian S_
2
user's latest post:
BUBBLE SORT
Published (2009-11-09 23:26:00)
If ever there was a first year programming homework question, it's a bubblesort implementation!!
Mycroft Holmes
1
user's latest post:
BUBBLE SORT
Published (2009-11-10 03:19:00)
I hope your tongue gets stuck firmly in your cheek ;P.
nlarson11
1
user's latest post:
BUBBLE SORT
Published (2009-11-09 23:21:00)
if your going to use a do and a for - then you need to make sure your not exceeding the size of the array. You can't compare if i+1 is greater then getupperbound(0). so you need to test for that. if you use a for and a for then it will do it for you. Dim sa() As String = { " a" , " z" , " e" , " b" , " j" , " k" , "...
The Man from U.N.C.L.E.
1
user's latest post:
BUBBLE SORT
Published (2009-11-10 04:22:00)
I remember developing a wonderful bit of code for a bubblesort algorithm. Imagine how gutted I was when I discovered that by writing a simple IComparer implementation I could take advantage of the much better bubblesort algorithim built in to .Net. Just like Microsoft to develop the same code already. Serves me right for not checking the documentation first.

Related threads on "CodeProject: Discussion Boards. Free source code and programming help":

Related threads on other sites:

Thread profile page for "BUBBLE SORT" on http://www.codeproject.com. This report page is a snippet summary view from a single thread "BUBBLE SORT", located on the Message Board at http://www.codeproject.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity