.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Insertion sort in c

Posted By:Nikhil Kumar       Posted Date: February 28, 2010    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  

insertion sort in c programming
 

#include
#include
#include
#include
 
 void main()
 {
 clrscr();
 
 int i,j,temp,a[4];
                for(i=0;i<5;i++)
                {
               cout<<"ENTER "<
               cin>>a[i];       
                         //input values
                }
               
 
                for(i=1;i<5;i++)
                 {
                  temp=a[i];
                  j=i-1;
           while(temp=0)
                 {
   a[j+1]=a[j];
   j=j-1;
   }
   a[j+1]=temp;
 
 }
                for(i=0;i<5;i++)
               {
                cout<<"THE"<
                cout<
               }
 getch();
 }
 
 
OUTPUT 
 
ENTER 1th ELEMENT:12
ENTER 2th ELEMENT:34
ENTER 3th ELEMENT:23
ENTER 4th ELEMENT:12
ENTER 5th ELEMENT:32
 
THE1IN NEW SORTED ARRAY IS:12
THE2IN NEW SORTED ARRAY IS:12
THE3IN NEW SORTED ARRAY IS:23
THE4IN NEW SORTED ARRAY IS:32
THE5IN NEW SORTED ARRAY IS:34


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend