Vamsi Pavan’s Place

When curiousity outbursts …..

Entries Tagged as 'C/C++'

Bubble Sort

April 15th, 2007 · No Comments · Algorithms, C/C++, Source Code

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

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Shell Sort

April 15th, 2007 · No Comments · Algorithms, C/C++, Source Code

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

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Insertion Sort

April 15th, 2007 · No Comments · Algorithms, C/C++, Source Code

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

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Selection Sort

April 15th, 2007 · No Comments · Algorithms, C/C++, Source Code

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 […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Fast Bit Counting Routines

October 17th, 2006 · No Comments · Algorithms, C/C++, Placements

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 & […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Virtual Functions (C++ Concepts)

October 6th, 2006 · No Comments · C/C++, Placements

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 […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Sum two numbers using bits

October 6th, 2006 · No Comments · Algorithms, C/C++

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

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Avoid multiple inclusion of header file

October 6th, 2006 · No Comments · C/C++, Placements

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 […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Interview questions

October 6th, 2006 · No Comments · C/C++, Placements

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 […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Bit wise operators

October 6th, 2006 · No Comments · C/C++, Placements

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 […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags: