Create 10 different arrays to sort

Posted 14 March 2012 - 02:34 PM

Hi, I'm writing a program that creates ten random arrays, sorts them using shell sort, and tracks the number of statements involved. However, my code loops the same number of statements ten times and then the Console Message after, I've tried moving the brackets around and have tried using a foreach statement, but I have a feeling that I am missing something that would make this work easier, any help would be appreciated! Here's my code:

Here is with the for each: The method is changed to public static int [] ShellSort (int [] values), with a return values, then I tried a for each, I get an error because "i" has been declared in parent scope:

I was wondering if doing it with loops would work best, or do I need to make another array for this?; Stuck and frustrated, there's more to this and I been working on it for three weeks now... Still feel lost. Thanks for your help.

Re: Create 10 different arrays to sort

you loop 10 times. Each time you increment 'statements'. THerefore it is always 10.

You never increment 'statements' so the result of statement/10 will always be the same.

This is obviously schoolwork so we can't just give you fixed code. All we can do is point out the error in your logic.

eric4215: What this shows us is that you aren't familiar with breakpoints and how to debug your own code. Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.