write a program for following a) bubble sorting b)insertions sorting c)selections sorting.Output
Answers
Answer:
Hey mate.....
Bubble sort...
#include (iostream. h)
#include (conio. h)
Void main()
{
Int a(8), i, j, t;
For (i=0 ; i<8; i++)
{
Cout <<"enter the no";
Cin >>a(i)
}
For (i =0; i < 8; i++)
{
for (i = 0; i <7; j++) ;
{
If (a[j] >a[j++])
{
t=a(j)
a(j) =a(j+1)
a(j+1) =t;
}
}
}
For (i=0; i <8; i ++)
{
Cout <<a(i) ;
}
getch() ;
}
Selection sort...
#incude (iostream. h)
#include (conio. h)
Void main ()
{
Int a(8), i, j, p, min, t;
For(I=0; I<8; I++)
{
Cout<<" enter the no";
Cin>>a(i)
}
For (I=0; I<8; I++)
{
Min = a (i)
P=1;
For (j=I+1; j<8; j++)
{
If (a(i)<min)
{
Min = a(i) ;
P= j;
}
}
t= a(p) ;
a(p) = a(i) ;
a(i) = t;
}
For (I=0; I<8;I++)
{
Cout << " a(i) ;
}
getch () ;
}
Insertion sort.....
#incude <iostream.h>
#include <conio. h>
Void main ()
{
Int a(8), I, j, t;
For (I=0; I<8; I++)
{
Cout <<"enter the no. "
Cin >>a (i) ;
}
For (I=0; I<8;I++)
{
t= a(i) ;
j=i-1;
While (a(j) > t && j >= 0 )
{
a (j+1) = a(j)
J =j-1;
}
a(j+1) = t;
}
For (I=0; I<8; I++)
{
Cout << a(i);
}
getch() ;
}
DONE
Hope it helps you... ❤