Problem implementing insertion sort

Joined
Aug 22, 2009
Messages
5
Reaction score
0
Hi,
Here is my code for insertion sort
/* Insertion sort


*/

#include <iostream.h>
#include <conio.h>
void InsertionSort(int []);
void main()
{
clrscr();
int a[10],i,j;
cout<<"Enter sequence to be sorted"<<endl;
for (i=0;i<10;i++)
{
cout<<"Enter number "<<i<<endl;
cin>>a;
}
InsertionSort(a);

getch();
}

void InsertionSort(int a[])
{
int i=0;
int value;
int j=0;
for (i=0;i<9;i++)
{


do
{
value = a[i+1];
if (a>a[i+1])
{
a[i+1] = a;
a = value;
if (i>0)
i--;
}
}while (i>0);
}

It is hanging in the while loop section
dunno according to me i have executed it properly
but its not working
please tell me where am i going wrong

Sincerely,
Rahul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top