This file contains 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
// A C++ program to demonstrate serialization and deserialiation of | |
// Binary Tree | |
#include <stdio.h> | |
#define MARKER -1 | |
/* A binary tree Node has key, pointer to left and right children */ | |
struct Node | |
{ | |
int key; | |
struct Node* left, *right; |
This file contains 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
// A C++ program to find minimum possible | |
// time by the car chassis to complete | |
#include <bits/stdc++.h> | |
using namespace std; | |
#define NUM_LINE 2 | |
#define NUM_STATION 4 | |
// Utility function to find minimum of two numbers | |
int min(int a, int b) | |
{ |
This file contains 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
// A Dynamic Programming based C++ program to find minimum | |
// number operations to convert str1 to str2 | |
#include <bits/stdc++.h> | |
using namespace std; | |
// Utility function to find the minimum of three numbers | |
int min(int x, int y, int z) | |
{ | |
return min(min(x, y), z); | |
} |
This file contains 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<stdio.h> | |
/*Function to return max sum such that no two elements | |
are adjacent */ | |
int FindMaxSum(int arr[], int n) | |
{ | |
int incl = arr[0]; | |
int excl = 0; | |
int excl_new; | |
int i; |
This file contains 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
// A Stack based C++ program to find next | |
// greater element for all array elements. | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* prints element and NGE pair for all | |
elements of arr[] of size n */ | |
void printNGE(int arr[], int n) { | |
stack < int > s; |
This file contains 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
// C++ program to rotate a matrix by 90 degrees | |
#include <bits/stdc++.h> | |
#define N 4 | |
using namespace std; | |
void displayMatrix(int mat[N][N]); | |
// An Inplace function to rotate a N x N matrix | |
// by 90 degrees in anti-clockwise direction | |
void rotateMatrix(int mat[][N]) |
This file contains 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
// C++ program to add two numbers | |
// represented by linked list | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* Linked list node */ | |
class Node | |
{ | |
public: | |
int data; |
This file contains 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
// CPP program to reverse a linked list | |
// in groups of given size | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* Link list node */ | |
class Node | |
{ | |
public: | |
int data; |
This file contains 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> | |
#include<stdlib.h> | |
using namespace std; | |
/* A simple stack class with basic stack funtionalities */ | |
class Stack | |
{ | |
private: | |
static const int max = 100; |
This file contains 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
// C++ program for a linear time solution for stock | |
// span problem without using stack | |
#include <iostream> | |
#include <stack> | |
using namespace std; | |
// An efficient method to calculate stock span values | |
// implementing the same idea without using stack | |
void calculateSpan(int A[], int n, int ans[]) | |
{ |