- 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
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