C++ Source code for String Replace : replacing a character with sequence of characters

Problem: find a give character to replace in  the source string and replace that character with given string or sequence of characters. Ex. ” I am a programmer” – Replace every occurrence of ” ” (space) with “%20″ string. Result should be “I%20am%20a%20progrmmer”. Solution: start with finding the index of  the ” “, remove this […]

Continue reading →

C++ programming source code to generate permutations of string

Problem: Write a  recursive program in C++ to generate permutations of a string. Ex. “abc”  -> abc acb bac bca cab cba Logic: “a” -> “ab” -> ab ba Similarly “abc” -> can be generated by inserting the new character in every position of the previous permutations of string(created with n-1 characters).

    […]

Continue reading →

C Programming source code for reversing the string In-Place

Problem : Reverse a string in-place. Given a char string  containing  ”String” should, changed into  ”gnirtS” after reversal. You should not use temporary buffer/string to hold new string. Solution : Create a char pointer pointing to the string. Move it till end. Run a loop where source pointer is less than end pointer. Move start […]

Continue reading →

How to find if a string is a permutation of another string

This algorithm will count the charterer’s  appearance in both the strings. Comparing the count will give tell if its permutation or not. Can be made more efficient in terms of processing and storage, will update soon.

 

Continue reading →

Source code for Quicksort algorithm in C programming

Quick sort is the one of the most efficient method to sort the elements. 1.  Select a pivot element. 2. Partition the array around pivot 3. Move the elements such that all elements less than partition element should come before the elements greater than pivot.

 

Continue reading →

Synchronization in win32 / MFC and Difference between critical sections, mutex and semophore objects

By multi threading many things can be done at once. One can divide a single task into multiple parts and execute simultaneously. More than one thread running simultaneously. On single processor systems its usually utilities the IO operation time with other concorruntly running thread to utilize CPU at its fullest strength. but on multiple processor […]

Continue reading →

Something about Writing Robust Functions

Almost any function, including Win32 and MFC routines, can fail. This is especially true in multitasking environments, such as Windows or Windows NT, where applications share limited system resources. You should anticipate this possibility, and write your programs accordingly. To properly code an application, you must anticipate possible errors by checking return values and taking […]

Continue reading →
Page 1 of 68123456»102030...Last »