473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ 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 2068
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 newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
7
8396
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 for the post on google. I was interested in the shell sort because I needed to sort long lists of data that may already be in order. For that reason I didn't want to use the arraylist's sort method, which uses quick sort (and has a worst case for...
6
38453
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 .bat file to do some installation, status of the installation will be displayed on the windows app, but don't want the dos window showed. I look at Microsoft.VisualBasic.Interaction.Shell, that Shell out command is asynchronous, right? If it...
4
3492
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 substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
5
3790
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 List<RoleData> GetRoles() { return GetRoles(null, false); }
2
11068
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': self.iplist.sort(cmp=self.RealtimeComparison) elif self.orderby == 'p': self.iplist.sort(cmp=self.ProcessingtimeComparison) # by default the order will just be the order that the IPs were in the reasoning log
3
1942
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 file, I have to restart the IDLE shell for the changes to take effect. It's pretty annoying. Assuming IDLE is already open, here are the steps that I typically take:
0
1752
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, another inputboxes will appear asking for the items to be sorted... then the items you inputed will be printed in the 1st listbox.. then when you click the 2nd cmd button the items in the first listbox will appear in the second listbox but they...
16
10766
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 Codes: Class ApplicationActionBarAdvisor:
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10005
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.