#include <stdio.h>
#include <stdlib.h>
void sortingArrayBySelection(int *Arr,int n);
void BubbleSort(int *ptr,int n);
int BinarySearch(int arr[],int data,int high ,int low);
void DisplayArray(int * p,int n);
void InsertionSort(int *ptr,int n);
int main()
{
int number[6]={12,232,22,23,54,2};
int element=6;
DisplayArray(number,element);
InsertionSort(number,element);
DisplayArray(number,element);
return 0;
}
void sortingArrayBySelection(int *Arr,int n)
{
int tem,loc;
for(int i=0;i<n;i++)
{
loc=i;
for(int j=i+1;j<n;j++)
{
if(*(Arr+j)<*(Arr+loc))
{
loc=j;
}
}
if(loc!=i)
{
tem=*(Arr+i);
*(Arr+i)=*(Arr+loc);
*(Arr+loc)=tem;
}
}
}
void BubbleSort(int *ptr,int n)
{
int tem;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(*(ptr+j)>*(ptr+j+1))
{
tem=*(ptr+j);
*(ptr+j)=*(ptr+j+1);
*(ptr+j+1)=tem;
}
}
}
}
void sortingInGeneral(int *ptr,int n)
{
int tem;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(*(ptr+i)>*(ptr+j))
{
tem=*(ptr+i);
*(ptr+i)=*(ptr+j);
*(ptr+j)=tem;
}
}
}
}
int BinarySearch(int arr[],int data,int high ,int low)
{
int mid;
while(high>=low)
{
mid=(high+low)/2;
if(arr[mid]==data)
{
return mid;
}
else if(arr[mid]>data)
{
high=mid-1;
}
else if(arr[mid]<data)
{
low=mid+1;
}
}
return -1;
}
void DisplayArray(int * p,int n)
{
for(int i=0;i<n;i++)
{
printf("%d ",*(p+i));
}
printf("\n");
}
void InsertionSort(int *ptr,int n)
{
int tem,j;
for(int i=1;i<n;i++)
{
tem=*(ptr+i);
j=i;
while(j>=0 && tem<*(ptr+j-1))
{
*(ptr+j)=*(ptr+j-1);
j=j-1;
}
*(ptr+j)=tem;
}
}
0 Comments