Skip to content

Instantly share code, notes, and snippets.

View rohit-nsit08's full-sized avatar

rohit jangid rohit-nsit08

View GitHub Profile
@rohit-nsit08
rohit-nsit08 / permute.c
Created August 12, 2011 19:17
permutes the given string
#include <stdio.h>
#include <string.h>
void swap(char*a,char*b)
{
char t;
t = *a;
*a=*b;
*b=t;
}
void permute(char* s, int i, int n)
@rohit-nsit08
rohit-nsit08 / paragraph_edit.c
Created August 12, 2011 16:58
deletes the extra space from the paragraph
#include <stdio.h>
#include <string.h>
char *s = "welcome to linux shell !";
char t[100];
//output = welcome to linux shell !
int main()
{
int i,j,flag=0;
@rohit-nsit08
rohit-nsit08 / common_ancestor.c
Created August 11, 2011 19:00
given pointer to two nodes in a tree, find their common ancestor.
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
struct node* left;
struct node* right;
int value;
}treenode;
int add_node(treenode**tree, int value);
@rohit-nsit08
rohit-nsit08 / treedepth.c
Created August 10, 2011 15:26
calculate the depth of a binary tree
void finddepth(Node *node,int depth){
if(node!=NULL){
depth=max(finddepth(node->left,depth+1), finddepth(node->right,depth+1) );
}
return depth;
}
On Mon
@rohit-nsit08
rohit-nsit08 / stringrev.c
Created August 10, 2011 13:08
string reverse c code
#include<stdio.h>
#include<string.h>
char s[] = "rohit";
void reverse(int);
int main()
{
printf("%s",s);
reverse(0);
printf("\n");
printf("%s",s);
@rohit-nsit08
rohit-nsit08 / hello gist
Created August 10, 2011 12:02
test gist
test gist application
@rohit-nsit08
rohit-nsit08 / tree.c
Created July 17, 2011 12:42
tree representation and node deletion
// creates a binary search tree
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
struct node* left;
struct node* right;
int value;
}treenode;
@rohit-nsit08
rohit-nsit08 / jsString
Created July 15, 2011 17:56
jsString in PIR
.namespace []
.sub main
$P1 = subclass 'String', 'jsString' # subclass default string pmc into jsString type
addattribute $P1, 'primitive'
$P7 = box "ROHIT"
$P2 = new 'jsString' # instantiate the new string object
setattribute $P2, "primitive", $P7
@rohit-nsit08
rohit-nsit08 / codegen.js
Created May 3, 2011 19:50
code generator
var indentChar = ' '; //4 spaces
function idt (lvl) {
if (lvl < 0) lvl = 0;
return Array(lvl+1).join(indentChar);
}
var codegens = exports.nodes = {
'Empty': function Empty_codegen () {
@rohit-nsit08
rohit-nsit08 / js.js
Created May 3, 2011 19:23
cafe.js module
var protoParser = require("./js/parser").parser,
nodes = require("./js/nodes"),
codegen = require("./js/codegen");
function Compiler () {
var constructors = {},
prototypes = {};
// Define AST nodes