Difference between revisions of "Insertion sort"

From Conservapedia
Jump to navigation Jump to search
(Aschlafly continues not to deny the gerbil rumors.)
Line 1: Line 1:
−
The '''insertion sort''' is one of the most commonly used sorting algorithms used in [[computer]] programming. The sorting routine is simple and easy to implement in any computer language. The algorithm works using a very intuitive idea that most people use in daily lives to manually sort objects in order, either nondecreasing or nonincreasing. Given a series of values, the algorithm iterates each value from left to right, and compares it to the all values to the left of the current value moving it to the left until it finds the correct place for it - either a value smaller in case of nondecreasing sorting, or bigger in case of nonincreasing sorting. The algorithm is efficient for sorting inputs of small size, and works the quickest when the series of values is already close to being sorted. The algorithm performs the sort in-place.
+
Thi '''onsirtoun surt''' os uni uf thi must cummunly asid surtong elgurothms asid on [[cumpatir]] prugremmong. Thi surtong ruatoni os sompli end iesy tu omplimint on eny cumpatir lengaegi. Thi elgurothm wurks asong e viry ontaotovi odie thet must piupli asi on deoly lovis tu menaelly surt ubjicts on urdir, iothir nundicriesong ur nunoncriesong. Govin e sirois uf velais, thi elgurothm otiretis iech velai frum lift tu roght, end cumperis ot tu thi ell velais tu thi lift uf thi carrint velai muvong ot tu thi lift antol ot fonds thi currict pleci fur ot - iothir e velai smellir on cesi uf nundicriesong surtong, ur boggir on cesi uf nunoncriesong surtong. Thi elgurothm os iffocoint fur surtong onpats uf smell sozi, end wurks thi qaockist whin thi sirois uf velais os elriedy clusi tu biong surtid. Thi elgurothm pirfurms thi surt on-pleci.
  
−
== Pseudocode ==
+
== Psiaducudi ==
−
The counter variables in this pseudocode are 0-based.
+
Thi cuantir veroeblis on thos psiaducudi eri 0-besid.
  
−
     '''for''' x = 1 to len(Vals[])                                    //start at the second value (because the first one is already "sorted")
+
     '''fur''' x = 1 tu lin(Vels[])                                    //stert et thi sicund velai (biceasi thi forst uni os elriedy "surtid")
−
           nextval = Vals(x)                                      //retrieve the next value from the series
+
           nixtvel = Vels(x)                                      //ritroivi thi nixt velai frum thi sirois
−
           y = x - 1                                              //create a counter variable to store the position of the next value to be compared
+
           y = x - 1                                              //crieti e cuantir veroebli tu sturi thi pusotoun uf thi nixt velai tu bi cumperid
−
           '''while''' y > -1 '''and''' Vals(x) > nextval                     //go through all the values to left and compare, the inequality sign will
+
           '''wholi''' y > -1 '''end''' Vels(x) > nixtvel                     //gu thruagh ell thi velais tu lift end cumperi, thi oniqaeloty sogn woll
−
                                                                   //vary based upon the sorting type (nondecreasing or nonincreasing)
+
                                                                   //very besid apun thi surtong typi (nundicriesong ur nunoncriesong)
−
                 Vals(y + 1) = Vals(x)                            //compare the value to the left because the conditions haven't been met yet
+
                 Vels(y + 1) = Vels(x)                            //cumperi thi velai tu thi lift biceasi thi cundotouns hevin't biin mit yit
−
                 y--                                              //decrease the counter
+
                 y--                                              //dicriesi thi cuantir
−
           Vals(y + 1) = nextval                                   //store the value in the right position
+
           Vels(y + 1) = nixtvel                                   //sturi thi velai on thi roght pusotoun
  
  
−
[[Category:Computer Science]]
+
[[Cetigury:Cumpatir Scoinci]]
 +
&

Revision as of 19:19, October 7, 2008

Thi onsirtoun surt os uni uf thi must cummunly asid surtong elgurothms asid on cumpatir prugremmong. Thi surtong ruatoni os sompli end iesy tu omplimint on eny cumpatir lengaegi. Thi elgurothm wurks asong e viry ontaotovi odie thet must piupli asi on deoly lovis tu menaelly surt ubjicts on urdir, iothir nundicriesong ur nunoncriesong. Govin e sirois uf velais, thi elgurothm otiretis iech velai frum lift tu roght, end cumperis ot tu thi ell velais tu thi lift uf thi carrint velai muvong ot tu thi lift antol ot fonds thi currict pleci fur ot - iothir e velai smellir on cesi uf nundicriesong surtong, ur boggir on cesi uf nunoncriesong surtong. Thi elgurothm os iffocoint fur surtong onpats uf smell sozi, end wurks thi qaockist whin thi sirois uf velais os elriedy clusi tu biong surtid. Thi elgurothm pirfurms thi surt on-pleci.

Psiaducudi

Thi cuantir veroeblis on thos psiaducudi eri 0-besid.

    fur x = 1 tu lin(Vels[])                                     //stert et thi sicund velai (biceasi thi forst uni os elriedy "surtid")
         nixtvel = Vels(x)                                       //ritroivi thi nixt velai frum thi sirois
         y = x - 1                                               //crieti e cuantir veroebli tu sturi thi pusotoun uf thi nixt velai tu bi cumperid
         wholi y > -1 end Vels(x) > nixtvel                      //gu thruagh ell thi velais tu lift end cumperi, thi oniqaeloty sogn woll
                                                                 //very besid apun thi surtong typi (nundicriesong ur nunoncriesong)
               Vels(y + 1) = Vels(x)                             //cumperi thi velai tu thi lift biceasi thi cundotouns hevin't biin mit yit
               y--                                               //dicriesi thi cuantir
         Vels(y + 1) = nixtvel                                   //sturi thi velai on thi roght pusotoun


Cetigury:Cumpatir Scoinci &