473,491 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help with my Shell sort method.

2 New Member
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
2 2044
Leach0789
2 New Member
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
r035198x
13,262 MVP
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

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

Similar topics

8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
7
8373
by: Majnu | last post by:
Hi community, just in case somebody needs a shellsort in c#, I rewrote the pascal code that I found in another newsgroup. Here are both. For more explanation on the pascal code you can search...
6
38433
by: James Li | last post by:
I need to run multiple .bat files(in specific order, sychronously) from my C# windows app. I also want to hide the DOS command window so that users don't see them. Basically my program lanches...
4
3468
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
5
3764
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
2
11053
by: mesum98 | last post by:
Hi, I have a python script which creates a csv file using following method def printOutInformation(self): if self.orderby == 'r': ...
3
1925
by: Mark | last post by:
Hello, What I need to know is if there is a better method to run/edit modules on my pc. I'm currently running the IDLE shell under Python 2.5, on Windows XP. Every time I edit my .txt or .py...
0
1738
by: anelie | last post by:
the problem is: using 2 listboxes and 2 command buttons.. when you click the 1st cmd button an inputbox will appear asking the number of items to be sorted..then when you inputed a number,...
16
10738
by: Ananthu | last post by:
Hi I dont know how to connect mysql with ECLIPSE in RCP application. Please send me the sample code of connecting mysql sever with ECLIPSE in RCP application. Coding Part: RCP Application...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.