Skip to content

Instantly share code, notes, and snippets.

@mycodeschool
mycodeschool / BalancedParentheses.cpp
Created October 29, 2013 00:49
C++ Program to check for balanced parentheses in an expression using stack.
View BalancedParentheses.cpp
/*
C++ Program to check for balanced parentheses in an expression using stack.
Given an expression as string comprising of opening and closing characters
of parentheses - (), curly braces - {} and square brackets - [], we need to
check whether symbols are balanced or not.
*/
#include<iostream>
#include<stack>
#include<string>
using namespace std;
@mycodeschool
mycodeschool / Queue_LinkedList.c
Last active December 2, 2023 11:22
Linked List implementation of Queue.
View Queue_LinkedList.c
/*Queue - Linked List implementation*/
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Two glboal variables to store address of front and rear nodes.
struct Node* front = NULL;
struct Node* rear = NULL;
View LevelOrder_CPP.cpp
/* Binary tree - Level Order Traversal */
#include<iostream>
#include<queue>
using namespace std;
struct Node {
char data;
Node *left;
Node *right;
};
@mycodeschool
mycodeschool / Stack_ArrayImplementation_OOP.cpp
Created October 8, 2013 02:44
An object oriented implementation of stack using arrays in C++.
View Stack_ArrayImplementation_OOP.cpp
// Stack - Object oriented implementation using arrays
#include <iostream>
using namespace std;
#define MAX_SIZE 101
class Stack
{
private:
int A[MAX_SIZE]; // array to store the stack
int top; // variable to mark the top index of stack.
@mycodeschool
mycodeschool / Stack_ArrayImplementation.C
Last active November 21, 2023 17:42
This is a basic array based implementation of stack data structure in C.
View Stack_ArrayImplementation.C
// Stack - Array based implementation.
// Creating a stack of integers.
#include<stdio.h>
#define MAX_SIZE 101
int A[MAX_SIZE]; // integer array to store the stack
int top = -1; // variable to mark top of stack in array
// Push operation to insert an element on top of stack.
@mycodeschool
mycodeschool / Queue_CircularArrayImplementation.cpp
Last active November 18, 2023 09:12
Queue - Array Implementation
View Queue_CircularArrayImplementation.cpp
/* Queue - Circular Array implementation in C++*/
#include<iostream>
using namespace std;
#define MAX_SIZE 101 //maximum size of the array that will store Queue.
// Creating a class named Queue.
class Queue
{
private:
int A[MAX_SIZE];
@mycodeschool
mycodeschool / DoublyLinkedList.c
Created November 12, 2013 11:38
Doubly Linked List implementation in C
View DoublyLinkedList.c
/* Doubly Linked List implementation */
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
View BSTDeletion_CPP.cpp
/* Deleting a node from Binary search tree */
#include<iostream>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
//Function to find minimum in a tree.
Node* FindMin(Node* root)
@mycodeschool
mycodeschool / BST_InorderSuccessor_CPP.cpp
Last active October 29, 2023 09:20
C++ program to find Inorder successor in a BST
View BST_InorderSuccessor_CPP.cpp
/* C++ program to find Inorder successor in a BST */
#include<iostream>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
//Function to find some data in the tree
@mycodeschool
mycodeschool / PreorderInorderPostorder_CPP.cpp
Last active October 29, 2023 09:20
Binary tree traversal: Preorder, Inorder, Postorder
View PreorderInorderPostorder_CPP.cpp
/* Binary Tree Traversal - Preorder, Inorder, Postorder */
#include<iostream>
using namespace std;
struct Node {
char data;
struct Node *left;
struct Node *right;
};