-1
//////This is a copied code for insertion sort
/////  It works for turbo c++ 1     
/////  in windows.
///     For students of nitc.
//    The program takes in size of array, and elements and sorts it.   




#include <iostream.h>
#include<conio.h>




//#define size 6


void insertion_sort(int x[],int length)

{

  int key,i;

  for(int j=1;j<length;j++)

  {

     key=x[j];

     i=j-1;

     while(x[i]>key && i>=0)

     {

	       x[i+1]=x[i];

	 i--;

     }

     x[i+1]=key;

  }

}



int main()

{
clrscr();
  int A[25];
  int size,i;
  int x;
  cout<<"Enter size of list";
  cin>>size;
  cout<<"Enter numbers";
  for(x=0;x<size;x++)
  {  cin>>A[x];  }

  cout<<"NON SORTED LIST:"<<endl;

  for(x=0;x<size;x++)

  {

       cout<<A[x]<<endl;

  }

  insertion_sort(A,size);

  cout<<endl<<"SORTED LIST"<<endl;

  for(x=0;x<size;x++)

  {

       cout<<A[x]<<endl;

  }
  getch();
  return 0;
}
Votes + Comments
What Chris said...
Pointless and didn't even read the rules
5
Contributors
4
Replies
51
Views
8 Years
Discussion Span
Last Post by sim2
0

Do you need help with anything? If you're just posting this and don't need help, you could put it into the code snippets section.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.