Quick Sort Program in C Using While Loop

Quick Sort Program in C Using While Loop. This sorting program is the best and fastest sort program among other sorting programs for beginners in every programming language. 

Quicksort program in a c programming language. quicksort program is based on the ascending order method and this how it works.

This is the fastest sorting algorithm in c programming language. This is program executed the result as soon as possible this is reason behind the name quick sort.

#include<stdio.h>
void sort(int num[25],int first,int last)
{
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j)
{
while(num[i]<=num[pivot]&&i<last)
i++;
while(num[j]>num[pivot])
j--;
if(i<j)
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
temp=num[pivot];
num[pivot]=num[j];
num[j]=temp;
sort(num,first,j-1);
sort(num,j+1,last);
}
}
int main()
{
int i, count, num[25];
printf("How many elements do you want?");
scanf("%d",&count);
printf("Enter %d elements: ", count);
for(i=0;i<count;i++)
scanf("%d",&num[i]);
sort(num,0,count-1);
printf("After sorting");
for(i=0;i<count;i++)
printf(" %d",num[i]);
return 0;
}

 

Output:

How many elements do you want? 3

Enter 3 elements:

34 56 78

After sorting 34 56 78

Return Statement in C Program

A return statement marks the end of a function’s execution and hands control back to the calling function. 

The calling function continues execution at the place where the call was made. 

A return statement can give the caller function a value. 

The data type of the value returned by the function is the return type. 

Some functions do what they’re supposed to do yet don’t return a value. 

The keyword void is used as the return type in this scenario.

 You pass a value to the parameter when you call a function.

Count Keyword in C

Counting is a technique for determining the amount of integers or objects in a list. 

Counting can help you keep track of how many loop iterations your program has gone through. 

Keywords are reserved terms in programming that have a specific meaning for the compiler.

Keywords are part of the syntax and can’t be utilised to identify something.

Array Method in C

An array is a collection of data elements of the same type stored in contiguous memory regions. 

Arrays are a derived data type in the c programming language that may hold primitive data types like int, char, double, float, and so on. 

An array is a grouping of variables with the same data type. 

In an array, you can store a collection of data of the same kind.

Any of the data types can contain an array. 

The size of the array must be constant. Using this program we can execute the program quick sort algorithm in c.