This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]);} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
NewerOlder