Electrofriends

Sorting of numbers

by Ranjith | November 4th, 2008.

Sorting means arranging a set of data in some order. There are different methods that are used to sort the data in ascending order. Some of the  methods are

  1. Selection sort
  2. Bubble sort
  3. Insertion sort

1. Selection sort

Here, to sort the data in ascending order, the 0th element is compared with all other elements. If it is greater than the compared element then they are interchanged. So after the first iteration smallest element is placed at the 0th position. The same procedure is repeated for the 1st element and so on. Read more…

2. Bubble sort

Here, to sort the data in ascending order, 0th element is compared with the 1st element. If it is greater than the 1st element then they are interchanged else remains same. Then 1st element is compared with 2nd element and procedure is continued. So after the first iteration largest element is placed at the last position. In the second iteration, the comparisons are made till the last but one position and now second largest element is placed at the second last position. After all the iterations, the list becomes sorted. Read more…

3. Insertion sort

Here, sorting takes place by inserting a particular element at the appropriate position. To sort the element in ascending order, in first iteration,1st element is compared with the 0th element. In the second iteration 2nd element is compared with 0th and 1st element. In general, in every iteration an element is compared with all the elements before it. While comparing if it is found that the element in question can be inserted at a suitable position, then space is created for it by shifting the other element one position to the right and inserting the element at the suitable position. This procedure is repeated for all the elements in the list. Read more…

In my program, you can enter 5 numbers which are to be sorted by any one of the above methods. After entering the numbers they are shown in red colour box and while comparison is done, the two elements which are compared are shown in green colour box. After sorting the elements, their permanent position is indicated by blue colour box. Click here to download the program.

Share and Enjoy:
  • Digg
  • Technorati
  • StumbleUpon
  • TwitThis
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Mixx
  • Yahoo! Buzz
  • LinkedIn
  • MySpace
  • FriendFeed
  • NewsVine
  • Netvibes
Similar Posts:

Leave a Reply

Electrofriends Comments
  • Alex: dear,i want to know more about car parking system if you interesting please give some information in addition...
  • Ranjith: You can give a link to this article in your website.
  • ashish: i need to design this car…would you pls send me all the details of it..what all stuff is required every...
  • Rinny Verma: hi………..plz send me the details n specifications of the robot….
  • omar: can u tell me how to control pitman motor using at89s51 through h bridge give ,jut move the motor in forward...
  • Copyright©2009 www.electrofriends.com All Rights Reserved. Powered by Dhyeya