Question- Implement the Selection Sort, Bubble Sort and Insertion sort
algorithms on a set of 25numbers. (Refer Figure 8.11 for the
logic of the algorithms)
− Insertion Sort
Solution-This program is kinda difficult for the beginners, honestly speaking i couldn't solve this problem for the first time. So, my suggestion is that if you can't solve it. don't break your heart.see, the solution and learn the techniques by seeing them.so,let's try to catch this solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[5];
int i,j,k,*l,t;
printf("Enter 5 numbers\n");
for(i=0;i<=4;i++)
scanf("%d",&arr[i]);
for(i=0;i<=4;i++)
{
t=arr[i];
for(j=0;j<i;j++)
{
if(t<arr[j])
{
for(k=i;k>=j;k--) /* watch out for this loop part, this part just interchanging elements till j */
arr[k]=arr[k-1];
arr[j]=t;
break;
}
}
}
l=&arr[0];
printf("Numbers in Ascending order\n");
for(i=0;i<=4;i++)
{
printf("%d\n",*l);
l++;
}
getch();
}
algorithms on a set of 25numbers. (Refer Figure 8.11 for the
logic of the algorithms)
− Insertion Sort
Solution-This program is kinda difficult for the beginners, honestly speaking i couldn't solve this problem for the first time. So, my suggestion is that if you can't solve it. don't break your heart.see, the solution and learn the techniques by seeing them.so,let's try to catch this solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[5];
int i,j,k,*l,t;
printf("Enter 5 numbers\n");
for(i=0;i<=4;i++)
scanf("%d",&arr[i]);
for(i=0;i<=4;i++)
{
t=arr[i];
for(j=0;j<i;j++)
{
if(t<arr[j])
{
for(k=i;k>=j;k--) /* watch out for this loop part, this part just interchanging elements till j */
arr[k]=arr[k-1];
arr[j]=t;
break;
}
}
}
l=&arr[0];
printf("Numbers in Ascending order\n");
for(i=0;i<=4;i++)
{
printf("%d\n",*l);
l++;
}
getch();
}
k8bet.com – Profile, Ratings, Competitors, & Alternatives
ReplyDeleteView k8bet.com (bet.com) profile, 우리카지노 마틴 revenue, industry 온카지노 and bk8