Skip to content

Instantly share code, notes, and snippets.

View shafiqshams's full-sized avatar
🏠
Working from home

Shafiq Shams shafiqshams

🏠
Working from home
View GitHub Profile
/* 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)
public class minHeap {
public int size;
public int [] mH;
public int position;
public minHeap(int size){
this.size=size;
mH = new int [size+1];
position = 0;
}
public void createHeap(int [] arrA){
@shafiqshams
shafiqshams / InsertionMinHeap.Java
Created February 21, 2017 09:46
Insert The new element is initially appended to the end of the heap (as the last element of the array). The heap property is repaired by comparing the added element with its parent and moving the added element up a level (swapping positions with the parent). This process is called "percolation up". The comparison is repeated until the parent is …
//The following code example demonstrates the algorithm
public void insert(Comparable x)
{
if(size == heap.length - 1) doubleSize();
//Insert a new item to the end of the array
int pos = ++size;
//Percolate up
@shafiqshams
shafiqshams / HeapSort.txt
Created February 22, 2017 09:59
HeapSort The algorithm runs in two steps. Given an array of data, first, we build a heap and then turn it into a sorted list by calling deleteMin. The running time of the algorithm is O(n log n). Example. Given an array {3, 1, 6, 5, 2, 4}.
1. build a heap 1, 2, 4, 5, 3, 6
2. turn this heap into a sorted list
deleteMin
1, 2, 4, 5, 3, 6 swap 1 and 6
6, 2, 4, 5, 3, 1 restore heap
2, 6, 4, 5, 3, 1
2, 3, 4, 5, 6, 1
deleteMin
@shafiqshams
shafiqshams / AlbumList.js
Created April 11, 2017 08:36
BoilerPlate for functional ReactNative component.
import React from 'react';
import { Text, View } from 'react-native';
const AlbumList = () => (
<View>
<Text> AlbumList </Text>
</View>
);
export default AlbumList;
@shafiqshams
shafiqshams / AlbumList.js
Created April 11, 2017 08:59
Refactored to Class Based Component.
import React, { Component } from 'react';
import { Text, View } from 'react-native';
class AlbumList extends Component {
render() {
return (
<View>
<Text> AlbumList!!! </Text>
</View>
);
@shafiqshams
shafiqshams / app.js
Created April 17, 2017 10:10
BoilerPlate for App.JS (ReactNative)
import React, { Component } from 'react';
import { Text, View } from 'react-native';
class App extends Component {
render() {
return (
<View>
<Text>An App!</Text>
</View>
);
@shafiqshams
shafiqshams / index.android.js
Created April 17, 2017 10:11
Index FILE used for android and ios both.
import { AppRegistry } from 'react-native';
import App from './src/app';
AppRegistry.registerComponent('LoginApp', () => App);
@shafiqshams
shafiqshams / app.component.ts
Created August 8, 2017 19:22
Redirect the user to main page if it's not authenticated, works even after logout. - [Angular 2 & Firebase App [Part 4] - Firebase Authentication]
import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from 'angularfire2';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@shafiqshams
shafiqshams / listings.component.ts
Created August 8, 2017 19:22
To avoid shows console error if the user is not authenticated to get listings from Firebase. [Angular 2 & Firebase App [Part 4] - Firebase Authentication]
import { Component, OnInit } from '@angular/core';
import { FirebaseService } from '../../services/firebase.service';
@Component({
selector: 'app-listings',
templateUrl: './listings.component.html',
styleUrls: ['./listings.component.css']
})
export class ListingsComponent implements OnInit {