Skip to content

Instantly share code, notes, and snippets.

@kodebinary
kodebinary / spiral-order-traversal.cpp
Last active April 22, 2019 13:46
Spiral order traversal of given binary tree, Complete explanation can be found here https://kodebinary.com/spiral-order-binary-tree-traversal
#include <iostream>
#include <stack>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
@kodebinary
kodebinary / find-next-node-in-given-tree.cpp
Last active April 22, 2019 13:45
Find next node in the same level for a given node, Complete solution can be explained here at https://kodebinary.com/find-next-node-in-the-same-level-for-given-node-in-a-binary-tree
#include <iostream>
#include <queue>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
@kodebinary
kodebinary / given-bt-full-or-not.cpp
Last active April 22, 2019 13:44
Find given binary tree is full or not, Explanation of the problem is at https://kodebinary.com/check-if-given-binary-tree-is-complete/
#include <iostream>
#include <queue>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
@kodebinary
kodebinary / find-sum-tree.cpp
Last active April 22, 2019 13:43
Find sum tree of given binary tree, Full solution with explanation can be found in: https://kodebinary.com/convert-binary-tree-to-its-sum-tree-in-place
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
};
@kodebinary
kodebinary / diameter-of-given-tree.cpp
Last active April 22, 2019 13:42
Find diameter of given binary tree, Full solution can be found in https://kodebinary.com/find-diameter-of-given-binary-tree
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
};
@kodebinary
kodebinary / mirror-of-binary-tree.cpp
Last active April 22, 2019 13:42
Find mirror of binary tree, complete solution with explanation is at https://kodebinary.com/find-mirror-of-a-binary-tree
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
};
#include <iostream>
#include <stack>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
@kodebinary
kodebinary / heap-data-structure.cpp
Last active May 16, 2020 12:16
Heap data structure example. Full article can be found here at https://kodebinary.com/heap-data-structure-minheap-and-maxheap-examples/
#include <iostream>
using namespace std;
class Heap
{
public:
int *inpArr;
int capacity;
@kodebinary
kodebinary / reverse-alternate-k-nodes.cpp
Created May 18, 2020 18:14
This code reverse every alternative k nodes in given singly linked list. Visit for full article at https://kodebinary.com/reverse-alternate-group-of-k-nodes-in-a-singly-linked-list/
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *next;
Node(int val)
{
#include <iostream>
#define MAX_HEAP_SIZE 1024
using namespace std;
class Heap
{
public:
int *inpArr;
int capacity;