int insertAt=0,index; for(index=insertAt+1;index if(a[insertAt] == a[index]) index+=1; else a[insertAt++] = a[index]; } insertAt–; Identification of duplicant element in an array Identify the element that is not repeating in an array of 2n+1 elements, in O(n) time X-or all the elements,Continue reading… Removing duplicates in an array in one pass
Prime number verification efficient way
If p is a prime number other than 2, then using formats thearom it follows the condition: 2^(p-1) mod p = 1 So In order to check whether a number is prime or not, we have to check the valueContinue reading… Prime number verification efficient way
Raising a number to a larger power ( power calculation)
We will see it with an example, Lets calculate pow(x,23) x^23 = x^22 * x x^22 = x^11 * x^11 x^11 = x^10 * x x^10 = x^5 * x^5 x^5
pseudo random number generator
The pseudo random numbers can be generated using linear congruential method. Successive members of the linear congruential sequence {x} are generated using the expression: X_n+1 = ( a*X_n + b) mod m
sizeof operator
sizeof(‘a’) = 4
Index into arrays
main () {
Function pointers, static char
typedef int abc (int a, char *b); int func2 (int a, char *b){
Delete a node from a Double Linked list, with out using any extra variables
DLNode *DelNode(DLNode *aHead, int DelValue) {
Reverse a Double Linked list
DLNode *revList(DLNode *aHead) {
Macros
Macro to swap any two variable int, char, float, struct etc.. /* Generic Swap macro*/ #define swap (a, b, type) {type t = a; a = b; b = t; } Call the macro like this: swap(a,b,int) swap(a,b,str)