Skip to content

Instantly share code, notes, and snippets.

View nihal-singh's full-sized avatar
📚
Always Learning !

NIHAL SINGH nihal-singh

📚
Always Learning !
View GitHub Profile
@nihal-singh
nihal-singh / PostFixEvaluation.cpp
Created August 27, 2018 20:37
Evaluate Postfix expression using stacks.
/*
Evaluation Of postfix Expression in C++
Input Postfix expression must be in a desired format.
Operands must be integers and there should be space or comma in between two operands.
Only '+' , '-' , '*' and '/' operators are expected.
*/
#include<iostream>
#include<stack>
#include<string>
@nihal-singh
nihal-singh / git_cheatsheet.txt
Last active August 31, 2018 09:53
Learn git in minutes
* git init -initialise a new git repository
[initially the new repository contains 0 commits]
[commit is a snapshot of git repository]
* git log - log of previous commits
['head' is the git name for current commit]
* git log -n 2 - shows only last 2 commits [n here means number]
* git log --graph --oneline master coins - [this will log the commits in one line (master and coins are the branch names) ]
Setting a remote repository on github
-----------------------------------------
* git remote - view current remotes
* git remote add origin https_repo_url - we can give any name instead of origin,it is the name in repo to refer to repo on github.
* git remote -v - To verify that the repo url was added correctly [v-verbose,provides more info]
* git push origin master - git push is used to push the local repo to github(remote)
[it takes two arguments - the remote I want to send changes to and name of local branch to push.]
* git pull origin master - git pull is used to pull the changes of the remote repo to the local directory.
* git fetch - fetches the remote commit of the branch to the local copy of the repository .we can then compare the commit made to the
local repo with the commit made remotely.
@nihal-singh
nihal-singh / create_example_file.py
Last active September 2, 2018 17:08
Image recognition using Python
def createExamples():
createFile = open('exFile.txt','a')
numberEx = range(0,10) #0.1,1.1,2.1
numberVer = range(1,10) #0.1,0.2,0.3
for eachNum in numberEx:
for eachVer in numberVer:
imgFilePath = 'images/numbers/'+str(eachNum)+'.'+str(eachVer)+'.png' #create image path
i = Image.open(imgFilePath)
iar = np.array(i)
// Infix to Postfix Expression
#include <iostream>
#include <string>
#include <stack>
using namespace std;
//*********************************************
//function to convert Infix to PPostfix
string InfixToPostfix(string );
@nihal-singh
nihal-singh / tree.txt
Last active September 12, 2018 13:37
tree - used to store heirarchical data( a non linear data structure)
collection of entities called nodes linked together to form a heirarchy.
depth of node (x) - no of edges b/w root and x
height of node - number of edges in longest path from node to leaf node.
height of tree = height of root
applications
storing natural heirarchical dat i.e , file system on computer
organise data for quick search insertion and deletion.ex - binary search tree
trie is used dictionaries
// Binary Search Tree - Implemenation in C++
// Simple program to create a BST of integers and search an element in it
#include<iostream>
using namespace std;
//Definition of Node for Binary search tree
struct BstNode {
int data;
BstNode* left;
BstNode* right;
};
/* Binary tree - Level Order Traversal */
#include<iostream>
#include<queue>
using namespace std;
struct Node {
char data;
Node *left;
Node *right;
};
/* Binary Tree Traversal - Preorder, Inorder, Postorder */
#include<iostream>
using namespace std;
struct Node {
char data;
struct Node *left;
struct Node *right;
};
//Pseudo code to check whether a binary tree is Binary Search Tree or not
bool checkBST(Node* root,int min,int max){
if(root == NULL)return true;
if(root->data > min && root->data < max && checkBST(root->left,min,root->data) && checkBST(root->right,root->data,max))
return true;
else return false;
}
isBST(Node* root){
return checkBST(root, INT_MIN, INT_MAX);