General > Algorithm >> Algorithm in CSharp Views : 29081
Rate This Article :

Insertion Sort

      public void InsertionSort(int[] intArray)

        {

            Console.WriteLine("==========Integer Array Input===============");

            for (int i = 0; i < intArray.Length; i++)

            {

                Console.WriteLine(intArray[i]);

            }

 

            int temp, j;

            for (int i = 1; i < intArray.Length; i++)

            {

                temp = intArray[i];

                j = i - 1;

 

                while (j >= 0 && intArray[j] > temp)

                {

                    intArray[j + 1] = intArray[j];

                    j--;

                }

 

                intArray[j + 1] = temp;

            }

 

            Console.WriteLine("==========Integer Array OutPut===============");         

            for (int i = 0; i < intArray.Length; i++)

            {

                Console.WriteLine(intArray[i]);

            }

        }

Output: Pass Un-sorted Integer Array to the above Method and get the array Sorted.

Insertion_Sort_Output.png

About Author
Raj Kumar
Total Posts 57
Developer in .Net!
Comment this article
Name*
Email Address* (Will not be shown on this website.)
Comments*
Enter Image Text*
   
View All Comments
luis
el progrma esta chingon grasias
Jody
Way to use the intneert to help people solve problems!
  Privacy   Terms Of Use   Contact Us
© 2016 Developerin.Net. All rights reserved.
Trademarks and Article Images mentioned in this site may belongs to Microsoft and other respective trademark owners.
Articles, Tutorials and all other content offered here is for educational purpose only and its author copyrights.