Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
bead_sort.c File Reference

Sorting of array list using bead sort More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for bead_sort.c:

Macros

#define BEAD(i, j)   beads[i * max + j]
 Create easy access of elements from a 2D matrix stored in memory as a 1D array.
 

Functions

void display (const int *arr, int n)
 Displays the array, passed to this method.
 
void bead_sort (int *a, size_t len)
 This is where the sorting of the array takes place.
 
int main (int argc, const char *argv[])
 Main function.
 

Detailed Description

Sorting of array list using bead sort

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Main function.

76{
77 int n;
78 printf("Enter size of array:\n");
79 scanf("%d", &n); // E.g. 8 1 2 3
80
81 printf("Enter the elements of the array\n");
82 int i;
83 int *arr = (int *)malloc(n * sizeof(int));
84 for (i = 0; i < n; i++)
85 {
86 scanf("%d", &arr[i]);
87 }
88
89 printf("Original array: ");
90 display(arr, n);
91
92 bead_sort(arr, n);
93
94 printf("Sorted array: ");
95 display(arr, n);
96
97 free(arr);
98 return 0;
99}
void bead_sort(int *a, size_t len)
This is where the sorting of the array takes place.
Definition bead_sort.c:37
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
Here is the call graph for this function: