Skip to content

Instantly share code, notes, and snippets.

View dumbbellcode's full-sized avatar
😀
learning every day

Sudheer Tripathi dumbbellcode

😀
learning every day
View GitHub Profile
@dumbbellcode
dumbbellcode / Polymorphism.java
Last active September 5, 2019 16:11
Polymorphism(Compiletime vs Runtime),Method Overloading and Method Overriding in java.
public class Polymorphism{
public static void main(String []args){
Base b1 = new Base();
Derived d1 = new Derived();
Base b2 = new Base();
Derived d2 = new Derived();
System.out.println("\n\n");
//Compiletime Polymorphism ->Method Overloading(i.e function overloading)
//(Methods have same name,diff parameters,inside same class)
/* Merge sort in C */
#include<stdio.h>
#include<stdlib.h>
// Function to Merge Arrays L and R into A.
// lefCount = number of elements in L
// rightCount = number of elements in R.
void Merge(int *A,int *L,int leftCount,int *R,int rightCount) {
int i,j,k;
//union find algorithm (not optimized)
#include <iostream>
using namespace std;
//remember arr[a] is parent of a
int unin(int arr[10],int x,int y)
{ while(arr[x]!=x){x=arr[x];}
while(arr[y]!=y){y=arr[y];}
arr[x]=arr[y];
return 0;
}
#include<bits/stdc++.h>
#include <iostream>
#include <set>
#include<map>
using namespace std;
void setDemo()
{
// In vectors we need to sort again and again after appending or updating values in order to perform lower and upper bounds (nlogn time)
// Set is better , every operation takes logn time.
set<int> S;
@dumbbellcode
dumbbellcode / BST (level order,preorder,inorder and postorder traversal).
Created May 17, 2019 08:46
BST (level order,preorder,inorder and postorder traversal).
//Program for (1).BFS. Level order traversal.
//(2). DFS(Preorder,Inorder,Postorder).
#include <iostream>
#include <queue>
using namespace std;
struct node
{ int data; node*left ; node*right ;//data,left child pointer,right ch ptr.
};
node* makenode(int data)
@dumbbellcode
dumbbellcode / Passing arrays to functions in c.
Created April 29, 2019 07:24
Passing arrays to functions in c.
// Passing 1D array
#include <stdio.h>
void fun(int a[],int m) //Here a[] is actually a pointer .We can also use int* a instead of int a[],both are same.
{
for(int i=0;i<m;i++) {scanf("%d",&a[i]);}
}
void fu(int a[],int b[],int m)
{
for(int i=0;i<m;i++) {b[i]=a[i];}
for(int i=0;i<m;i++) {printf("%d ",b[i]);}
@dumbbellcode
dumbbellcode / Binary tree
Last active May 16, 2019 05:28
Binary tree (construction,find min element,find height,etc)
#include <iostream>
using namespace std;
struct node
{ int data; node*left ; node*right ;//data,left child pointer,right ch ptr.
};
node* makenode(int data)
{ //this function creates a new node pointer,makes that pointer point to a node,sets node values and returns that pointer.
node* x= new node();
x->left = NULL;
@dumbbellcode
dumbbellcode / InfixToPostfix.cpp
Created April 25, 2019 12:45 — forked from mycodeschool/InfixToPostfix.cpp
Infix to Postfix conversion in C++ using stack. We are assuming that both operators and operands in input will be single character.
/*
Infix to postfix conversion in C++
Input Postfix expression must be in a desired format.
Operands and operator, both must be single character.
Only '+' , '-' , '*', '/' and '$' (for exponentiation) operators are expected.
*/
#include<iostream>
#include<stack>
#include<string>
@dumbbellcode
dumbbellcode / linkedlist2.cpp
Created April 25, 2019 05:36
Linked list implementation of stack
#include <iostream>
using namespace std;
struct node
{ int data;
node* next;
};
node* head;
void push(int x)
{ node* temp=new node();
temp->data=x; // the new element pushed in comes between head and first node
@dumbbellcode
dumbbellcode / linkedlist1.cpp
Last active April 24, 2019 18:51
Everything with linked lists(C++ insertion,printing,deleting elements,reversing,printing using recursion,reversing using recursion,etc in linked lists.)
//linked lists node insertion,printing,deletion and reversing
#include <iostream>
using namespace std;
struct node
{
int data;
node* next;
};
node* head;
void insert(int,int);