#include<stdio.h>
#include<conio.h>
void sort(int arr_new[],int i,int n)
{
int temp;
if(i<n-1)
{
if(arr_new[i]>arr_new[i+1])
{
temp=arr_new[i];
arr_new[i]=arr_new[i+1];
arr_new[i+1]=temp;
}
sort(arr_new,++i,n);
sort(arr_new,0,n-i);
}
}
void main()
{
clrscr();
int arr[10]={3,8,7,6,0,77,3,90,3,13};
int i;
printf("Array elements before sorting");
for(i=0;i<10;i++){
printf(" %d",arr[i]);
}
sort(arr,0,10);
printf("Array elements after sorting");
for(i=0;i<10;i++)
{
printf(" %d",arr[i]);
}
getch();
}
output
Array elements before sorting
3 8 7 6 0 77 3 90 3 13
Array elements after sorting
0 3 3 3 6 7 8 13 77 90
#include<conio.h>
void sort(int arr_new[],int i,int n)
{
int temp;
if(i<n-1)
{
if(arr_new[i]>arr_new[i+1])
{
temp=arr_new[i];
arr_new[i]=arr_new[i+1];
arr_new[i+1]=temp;
}
sort(arr_new,++i,n);
sort(arr_new,0,n-i);
}
}
void main()
{
clrscr();
int arr[10]={3,8,7,6,0,77,3,90,3,13};
int i;
printf("Array elements before sorting");
for(i=0;i<10;i++){
printf(" %d",arr[i]);
}
sort(arr,0,10);
printf("Array elements after sorting");
for(i=0;i<10;i++)
{
printf(" %d",arr[i]);
}
getch();
}
output
Array elements before sorting
3 8 7 6 0 77 3 90 3 13
Array elements after sorting
0 3 3 3 6 7 8 13 77 90
No comments:
Post a Comment