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
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
Tags:
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
Tags:
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
Tags:
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;
// start reading nums
for(i=0;i arr[j])
swap(arr,i,j);
// print sorted arr
for(i=0;i
Please point your web link to this page if you are using this code for any purposes.
Bookmark it!
These icons […]
Tags:
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 int n)
{
int count=0;
while (n)
{
count += n & […]
Tags:
Virtual Functions
Design Patterns
Important C/C++ Basic Concepts
Program startup and termination are facilitated by using two functions: main and exit. Other startup and termination code may be executed.
The arguments in the prototype
int main( int argc[ , char *argv[ ] [, char *envp[ ] ] ] );
or
int wmain( int argc[ , wchar_t *argv[ ] [, wchar_t […]
Tags:
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
Tags:
Generally, a header (.h) file should have (A header file need not have a .h extension, its just a convention):
1. Macro definitions (preprocessor #defines).
2. Structure, union, and enumeration declarations.
3. Any typedef declarations.
4. External function declarations.
5. Global variable declarations.
Put declarations / definitions in header files if they will be shared between several other files. If some […]
Tags:
Linked Lists
Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
Write a C program to implement a Generic Linked List.
How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list.
How do you find the […]
Tags:
Bit wise operators and % operator cannot be applied to float
fmod() is to find modulus for float as % is for int
but it needs math.h;
This can be used to detect whether a given number is an integer or a float value;
fmod(Var,1.0)==0 ? printf(”Yes it is integer”) : printf(”Not an integer”);
Bit fields
Bit fields can be used […]
Tags: