By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

Need help with my Shell sort method.

P: 2
hey guys. I'm new to this forum. I'm taking computer science at my high school this year, and was wondering if you could help me out with my shell sort program im writing. Here's the method that I wrote...

Expand|Select|Wrap|Line Numbers
  1. static void sort(int [] list, int size)
  2.     {
  3.         for(int gap = size / 2; gap > 0; gap /= 2)
  4.         {
  5.             for(int c = 0; c < gap; c++)
  6.             {
  7.                 if(list[c] < list[c+gap])
  8.                     {
  9.                         int temp = list[c];
  10.                         list[c] = list[c+gap];
  11.                         list[c+gap] = temp;
  12.                     }
  13.             }
  14.         }
  15.     }

If it helps, heres the output that I get.

Inputed Order:
1
2
3
4
5
6
7
8
9
10

Descending Order:
9
8
6
7
10
1
2
3
4
5


Thanks alot!
Jan 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
I dont think thath I quite understand the concept of shell sort. And I think thats why I cant quite get my method to work.
Jan 4 '07 #2

10K+
P: 13,264
I dont think thath I quite understand the concept of shell sort. And I think thats why I cant quite get my method to work.
do you understand the insertion sort alogorithm first? If you do then have a look at this http://en.wikipedia.org/wiki/Shell_sort and try the code again. If you still do not understand it post again explaining where you do not understand.
Jan 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.