Skip to content

Instantly share code, notes, and snippets.

@mbalayil
mbalayil / swap_add_mul.c
Created May 3, 2011 06:16
Swapping without using a temporary variable in C - Addition & Subtraction
/**
* Swapping without using a temporary variable in C
* (Addition & Subtraction)
**/
#include<stdio.h>
int main(void)
{
int a = 5, b = 10;
@mbalayil
mbalayil / quick_sort.c
Created May 2, 2011 18:12
Quick Sort using recursion in C
/** Divide : Partition the array A[low....high] into two sub-arrays
* A[low....j-1] and A[j+1...high] such that each element
* of A[low....j-1] is less than or equal to A[j], which
* in turn is is less than or equal to A[j+1...high]. Compute
* the index j as part of this partitioning procedure.
* Conquer : Sort the two sub-arrays A[low....j-1] and A[j+1....high]
* by recursive calls to quicksort
**/
#include<stdio.h>
@mbalayil
mbalayil / merge_sort.c
Created April 1, 2011 18:21
Merge Sort using recursion in C
/**
* Divide : Divide the n-element array into two n/2-element
* sub-arrays
* Conquer : Sort the two sub-arrays recursively using
* merge sort
* Combine : Merge the two sorted subsequences to form the
* sorted array
**/
#include<stdio.h>