 # C Programming Code Examples

## C > Sorting Searching Code Examples

### C Program to Implement Pigeonhole Sort

``` C Program to Implement Pigeonhole Sort This C Program implement pigeonhole sort. Pigeonhole sorting, also known as count sort, is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values (N) are approximately the same. It requires O(n + N) time #include <stdio.h> #define MAX 7 void pigeonhole_sort(int, int, int *); void main() { int a[MAX], j, min, max; printf("enter the values into the matrix :"); for (j = 0; j < MAX; j++) { scanf("%d", &a[j]); } min = a; max = a; for (j = 1; j < MAX; j++) { if (a[j] < min) { min = a[j]; } if (a[j] > max) { max = a[j]; } } pigeonhole_sort(min, max, a); printf("Sorted order is :\n"); for (j = 0; j < MAX; j++) { printf("%d", a[j]); } } /* sorts the array using pigeonhole algorithm */ void pigeonhole_sort(int mx, int ma, int * a) { int size, count = 0, j; int *current; current = a; size = ma - mx + 1; int holes[size]; for (j = 0; j < size; j++) { holes[j] = 0; } for (j = 0; j < size; j++, current++) { holes[*current-mx] += 1; } for (count = 0, current = &a; count < size; count++) { while (holes[count]--> 0) { *current++ = count + mx; } } } ```

C Codes Multiply 2 Numbers use Function - Create a user defined function product() that multiplies the numbers that we are passing to it during function call. This c function returns the product of these numbers. To understand

C++ Language Character & String Literals - When writing both single "character & string" literals, it is Necessary to 'Put the Quotation' marks surrounding them to distinguish them from possible variable identifiers or reserved

Convert Binary Code of a Number into its - C Programming Language code to convert binary code of a number into its equivalent gray's code without using recursion. Gray is also represented using 0s and 1s. Speciality

Code to find Sum of Digits using recursion - Write a Recursive Function in C Language to calculate sum of digits of a number. Declare Recursive Function to find sum of digits of a number. First give a meaningful name to the

C++ Wheel Sieve Generate Prime Number - This is a C++ Program to find 'Prime number' between the given range using 'Wheel Seive' method. "Wheel Factorization" is a graphical method for manually performing preliminary

Singly Linked list Program Using functions - In C++, under the simplest form, each node is composed of data and a reference ('a link') to the next node in the sequence. This structure allows for efficient insertion or removal of the

C Language Finding the Sum of G.P Series - C Language program is used to Find the Sum of the geometric progression series. Here G.P stands for geometric progression. Geometric progression, or GP, is a sequence where each

C Code Implement Queue with Linked List - C language program code implements queue using linked list. Queue is a particular kind of abstract Data Type or collection in which the entities in the collection are kept in order and