The source code for bubble sort. #include #define NUM 6 void swap(int arr[], int i, int j) { int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } main() { int arr[NUM],i,j; // start reading nums for(i=0;i
Category: Algorithms
Shell Sort
Source code for shell sort is provided below. #include #define NUM 6 main() { int arr[NUM],i,j, incr=2; // start reading nums for(i=0;i
Insertion Sort
Source code for Insertion sort in C language. #include #define NUM 6 main() { int arr[NUM],i,j; // start reading nums for(i=0;i
Selection Sort
The code for the selection sort in C lang is provided below. #include #define NUM 6 void swap(int arr[], int i, int j) { int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } main() { int arr[NUM],i,j; //Continue reading… Selection Sort
Fast Bit Counting Routines
A common problem asked in job interviews is to count the number of bits that are on in an unsigned integer. Here are seven solutions to this problem. Source code in C is available. Iterated Count int bitcount (unsigned intContinue reading… Fast Bit Counting Routines
A program to draw a circle
I recently came across a book called Programming Interviews Exposed. I’ve never actually read one of these books which purports to tell how to answer interview questions at tech companies. If you’re thinking about buying this book to help youContinue reading… A program to draw a circle
Polynomial evaluation
Paranthesization of polynomial evaluation A polynomial of degree N-1 will have N terms (including the constant). And a product of two polynomials each of degree N-1 will have a degree of 2N-2 with 2N-1 terms. Evaluation of a polynomial functionContinue reading… Polynomial evaluation
Sum two numbers using bits
int main(int argc,char *argv[]){ int a=atoi(argv[1]),b=atoi(argv[2]),sum,carry; sum = a^b; carry = a&b; while(carry){ carry = carry
Fibonacci numbers
f(n) = (1/sqrt(5)) * (((1+sqrt(5))/2) ^ n – ((1-sqrt(5))/2) ^ n) a Number N is fibacci number iff 5*N*N+4
Heterogenious linked list
If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It isContinue reading… Heterogenious linked list