Featured post

-Write C program to find even and odd number using macro

-Write C program to find even and odd number using macro #include<stdio.h> #define number(n)((n%2==0)?1:0) int main() { int num; printf("enter any number"); scanf("%d",&num); if(number(num)) printf("number is even"); else printf("number is odd"); return 0; } ***************************Output*********************** amr@amrj-virtual-machine:~$ gccevenodd.c amr@samr-virtual-machine:~$ ./a.out enter any number 2 number is evensmj@amr-virtual-machine:~$

Write a program to find the Seven elements using Quick Sort in c(Data Structure and Algorithm).

                                                DATA STRUCTURE AND ALGORITHM

Write a program to find the  Seven elements using Quick Sort in c(Data Structure and Algorithm).

 

#include<stdio.h>

void quick_sort(int a[10],int low,int high);

void main()

{

 int pivot,high,low,i,j,n,a[10];

printf("how many element you want to sort");

scanf("%d",&n);

printf("enter the element of an array");

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

quick_sort(a,0,n-1);

low=0;

high=n-1;

quick_sort(a,low,high);

printf("after sorting the element are");

for(i=0;i<n;i++)

printf("%d\t",a[i]);

}

void quick_sort(int a[10],int low,int high)

{

 int pivot,i,j,t;

if(low<high)

{

pivot=a[low];

i=low;

j=high;

while(i<j)

{

while(pivot>=a[i] && i<=high)

i++;

while(pivot<a[j] && j>=low)

j--;

if(i<j)

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

a[low]=a[j];

a[j]=pivot;

quick_sort(a,low,j-1);

quick_sort(a,j+1,high);

}

}

                       OUTPUT

amr@amr-virtual-machine:~$ gcc Quick.c

amr@amr-virtual-machine:~$ ./a.out

how many element you want to sort8

enter the element of an array9

7

4

5

1

6

8

4

after sorting the element are1  4    4    5    6    7    8


Comments

Post a Comment

Welcome to FlutterForge please write your Query

Popular posts from this blog

-Write C program to find even and odd number using macro

BCA (SCIENCE) JAVA PRACTICAL SLIPS PAGES.(JAVA) UNIVERSITY OF PUNE

How to OCR Text Extraction in Flutter Using Google ML Kit