Skip to content

Instantly share code, notes, and snippets.

View alokshanhbti's full-sized avatar

Alok Shankar alokshanhbti

View GitHub Profile
@alokshanhbti
alokshanhbti / gcd.cpp
Created March 11, 2019 00:44 — forked from mycodeschool/gcd.cpp
GCD: Brute force and Euclid's algorithm
#include<algorithm>
using namespace std;
int euclid_gcd(int a, int b)
{
while (b != 0)
{
int r = a % b;
a = b;
@alokshanhbti
alokshanhbti / Stack_ArrayImplementation.C
Created March 11, 2019 00:43 — forked from mycodeschool/Stack_ArrayImplementation.C
This is a basic array based implementation of stack data structure in 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.
@alokshanhbti
alokshanhbti / Stack_ArrayImplementation_OOP.cpp
Created March 11, 2019 00:43 — forked from mycodeschool/Stack_ArrayImplementation_OOP.cpp
An object oriented implementation of stack using arrays in C++.
// 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.
@alokshanhbti
alokshanhbti / BalancedParentheses.cpp
Created March 11, 2019 00:43 — forked from mycodeschool/BalancedParentheses.cpp
C++ Program to check for balanced parentheses in an expression using stack.
/*
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;
/* 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];
@alokshanhbti
alokshanhbti / DoublyLinkedList.c
Created March 11, 2019 00:43 — forked from mycodeschool/DoublyLinkedList.c
Doubly Linked List implementation in C
/* Doubly Linked List implementation */
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
@alokshanhbti
alokshanhbti / Queue_LinkedList.c
Created March 11, 2019 00:43 — forked from mycodeschool/Queue_LinkedList.c
Linked List implementation of Queue.
/*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;
/*
Evaluation Of postfix Expression in C++
Input Postfix expression must be in a desired format.
Operands must be integers and there should be space in between two operands.
Only '+' , '-' , '*' and '/' operators are expected.
*/
#include<iostream>
#include<stack>
#include<string>
@alokshanhbti
alokshanhbti / InfixToPostfix.cpp
Created March 11, 2019 00:42 — 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>
/* Binary tree - Level Order Traversal */
#include<iostream>
#include<queue>
using namespace std;
struct Node {
char data;
Node *left;
Node *right;
};