Need help with my Shell sort method.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leach0789
    New Member
    • Jan 2007
    • 2

    #1

    Need help with my Shell sort method.

    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...

    Code:
    static void sort(int [] list, int size)
    	{
    		for(int gap = size / 2; gap > 0; gap /= 2)
    		{
    			for(int c = 0; c < gap; c++)
    			{
    				if(list[c] < list[c+gap])
    					{
    						int temp = list[c];
    						list[c] = list[c+gap];
    						list[c+gap] = temp;
    					}
    			}
    		}
    	}

    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!
  • Leach0789
    New Member
    • Jan 2007
    • 2

    #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.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Leach0789
      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.

      Comment

      Working...