/* Ajith - Syntax Higlighter - End ----------------------------------------------- */

6.10.2013

How to narrate a story to computer scientist


If it brings back old memories or a smile then I hope you understood the characters in STORY.

3.15.2013

Death of Google Reader - Journey towards alternatives

Flashback

Long Long ago when INTERNET is booming up with so many websites its really hard to follow the interesting one. Its quite clumsy to go around miliions of sites to check for new posts.

Am I Doomed ?

No, you are not. RSS feed mechanism is the answer.


Just follow the RSS feed of your favourite site and the RSS reader will maintain the unread articles, favourite articles and so on. Voilla simple and effective solution to follow various sites.

3.13.2013

Divide a number by 3 without using any arithmetic operators

How to divide a number by 3 without using operators + - / * %

NOTE: I am just trying to collect various answers down in this post available across multiple sites in internet as mentioned in references.

Solution 01:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fp=fopen("temp.dat","w+b");
    int number=12346;
    int divisor=3;
    char *buf = calloc(number,1);
    fwrite(buf,number,1,fp);
    rewind(fp);
    int result=fread(buf,divisor,number,fp);
    printf("%d / %d = %d", number, divisor, result);
    free(buf);
    fclose(fp);
    return 0;
}

Checking Balance of Symbols in a expression

This article is part of article series - "Datastructures"

A balanced expression contains right number of closing and open braces.

For example:

  • [[ - unbalanced expression
  • []{}() - balanced expression
  • [(*)] - balanced expression

Let us see how to find if an expression is balanced or not by checking for following operators [ ] { } and ( ) in the given expression.

Using Stacks



2.05.2013

Conversion from Infix to Postfix

This article is part of article series - "Datastructures"

Converting a Fully Parenthesized Infix expression into Postfix expression  


Analysis:

Five types of input characters

  • Opening parentheses
  • Operands
  • Operators
  • Closing parentheses
  • New line character (\n)

Pseudocode:


********************************************************  
 Function  : main  
  
 Calls     : createStack  
             freeStack                
             pushIntoStack   
             popFromStack   
  
 Called by : NONE   
  
 Input   
 Parameters: Accepts input expression for processing  
    
 Returns   : Converts Fully paranthesized INFIX 
             expression into POSTFIX expression
******************************************************** 

SET i to 0
GET infix expression from user into input_array
SET var with input_array[i]

CALL createStack

WHILE var != end of string

  IF var equals to '(' THEN
  
    CALL pushIntoStack (stack, var)  

  ELSE IF var is a number THEN        
  
    PRINT var  

  ELSE IF var is an arithmetic operator THEN
  
    CALL pushIntoStack (stack, var) 
    
  ELSE IF var equals to ')' THEN

    WHILE stackTop != '('

      IF stackTop is an arithmetic operator THEN

        PRINT stackTop
        popFromStack (stack)

      ENDIF
    
    ENDWHILE

    popFromStack (stack)

  ENDIF

  SET var with input_expression[INCREMENT i]

ENDWHILE

CALL freeStack (stack)