//////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;
}
Freaky_Chris commented: Pointless and didn't even read the rules +0
William Hemsworth commented: What Chris said... -1

Recommended Answers

What's your problem?

Jump to Post

All 4 Replies

Member Avatar

What's your problem?

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.

thanks alot that insertion sort was a big help

thanks a lot....this was a big help....
:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.