Search Books and Solutions Manual

Hire My Expertise

if you need help regarding semester projects, assessment/assignment related to web development(php, html, css, javascript, ajax,) or java, c, c++, c#, asp.net, ror, scala or pythn then please hire my expertise. i am professionally software developer. working as a Android & Web Developer. i'll provide my best to fulfil task in time.If you need new website or app or require any kind of digital resource, Please feel free to get in touch without wasting any single minute. I would love to work with you. Please send your requirement. i'll come back to you in time.

For more information, feel free to contact: muhammadmustafa1@hotmail.com

Free Books and Solutions Manual Headline

Monday, 23 May 2011

Sorting In C++


 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

  Selection sort

  Bubble sort

  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.

 

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

 
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.
Download the sample Program Here