Monday, April 4, 2011

SORTING c++

| Monday, April 4, 2011 | 0 comments

1. DefinitionSorting is the process of arranging a set of objects according to certain rules or composition.The order of the object is dapt ascending (ascending = from small data into larger data) or decreased (descending = from large data into smaller data).sorting algorithmThere are so many existing sorting algorithms, but here we will learn 3 methods are:- Ordering Bubbles (bubble sort)- Maximum / Minimum (maximum / minimum sort)- Ordering insert (Insertion Sort)

2. Ordering Bubbles (bubble sort)Bubble sorting method (bubble sort), inspired by soap bubbles in the water. Because the soap bubble density is lighter than water density, the soap bubbles will always float.The principle of flotation is also used in sequencing the bubble. Most valuable elements of small "diapungkan", which means raised to the top (or the ends of the far left) through the exchange. Flotation process is performed N times steps. In step I, array [1 .. N] will consist of 2 parts:• Parts that have been sorted ie L [1] .. L [i].• Parts that have not been sorted L [I +1] .. L [n].Bubble Sorting Algorithm To get the array sorted ascending yan, a process that must be done at each step as follows:• Step 1: Start of element K = N, N-1, N-2, .. 2 compare L [K] if L [K] <L [K-1], exchange L [K] with L [K- 1].• At the end of step 1, the elements L [1] contains the minimum price the first.• Step 2: Start of element K = N, N-1, N-2, .. 3 compare L [K] if L [K] <L [K-1], exchange L [K] with L [K- 1].• At the end of step 2, the element L [2] contains the minimum price the second and L [1] .. L [2] sorted ..• Step 3: Start of element K = N, N-1, N-2, .. 4 compare L [K] if L [K] <L [K-1], exchange L [K] with L [K- 1].• At the end of step 3, the elements of L [3] contains the minimum price the third and L [1] .. L [3] sorted ..• ... ...• N-Step 1: Start of element K = N, N-1, N-2, .. 4 compare L [K] if L [K] <L [K-1], exchange L [K] with L [ K-1].

3. Ordering Maximum / Minimum
 sequencing method called sequencing maximum / minimum because it is based on
 selection of the maximum or minimum element then
 exchange element of maximum / minimum with terujung element array (element left end or right end of elements).
 Further terujung elements that we are "isolated" and not be included in the next process. Because the primary process is the selection of elements in the sortingmaximum / minimum, this method is called the method of selection (selection sort).


 Maximum Ordering Algorithm
 Elements to be sorted ascending:
 Step 1: Determine the Maximum Price in L1 [1 .. N] Interchange the maximum price of DNG L [N]
 Step 2: Determine the Maximum Price in L1 [1 .. N-1] Interchange the maximumprice of DNG L [N-1]
 Step 3: Determine the Maximum Price in L1 [1 .. N-2] Interchange the maximumprice of DNG L [N-2]
 ... ... ..
 N-Step 1: Determine the Maximum Price in L1 [1 .. 2] Interchange the maximumprice of DNG L [2].

4. Insert Ordering
 From the name, sorting insert (insertion sort) is a method of sorting an array elementby inserting in the right position.
 Searching the right position by successive searches. During the search for the right position is shifting array element.
Algorithm For Sorting Ascending
 Suppose: L [1] considered to have its place.
 Step 2: L [2] to look for the right place at the L [1 .. 2] by shifting the elements L [1] tothe right if L [1] is larger than L [2]. Suppose that the exact position of the element isinserted K L [2] in K.
 Step 3: L [3] to look for the right place at the L [1 .. 3] by shifting the elements L [1 ..2] to the right if L [1 .. 2 larger than L [3]. Suppose that the exact position of the element is inserted K L [3] in K.
 Step 4: L [4] to look for the right place at the L [1 .. 4] by shifting the elements L [1 ..4] to the right if L [1 .. 4] is larger than L [4]. Suppose that the exact position of the element is inserted K L [4] in K.
 ... ..
 Step N: L [N] to look for the right place at the L [1 .. N] by sliding element L [1 .. N tothe right if L [1 .. N] is larger than L [N]. Suppose that the exact position of the elementis inserted K L [N] in K.

0 comments:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment

thank you for visiting my blog and comment here. I hope the commentary contains a comment which intend to build and repair. criticism and suggestions I gladly accept.

Popular Posts

 

Total Pageviews

stat

© Copyright 2010. http://programminghaha.blogspot.com . All rights reserved | http://programminghaha.blogspot.com is proudly powered by Blogger.com | Template by o-om.com - zoomtemplate.com