Skip to content

Instantly share code, notes, and snippets.

public static void insertionSort (int[] inputData) {
for (int forwardPointer = 1; forwardPointer < inputData.length; forwardPointer++) {
int selectElement = inputData[forwardPointer];
int reversePointer = forwardPointer -1;
while (reversePointer >= 0 && selectElement < inputData[reversePointer]) {
inputData[reversePointer+1] = inputData[reversePointer];
reversePointer--;
}
inputData[reversePointer + 1] = selectElement;
}
func insertionSort(inputData: inout [Int]) {
for forwardPointer in 1...inputData.count - 1 {
let selectElement = inputData[forwardPointer] //Select the element
var reversePointer = forwardPointer - 1 //Set the reverse pointer
while (reversePointer >= 0 && selectElement < inputData[reversePointer]) {
inputData[reversePointer + 1] = inputData[reversePointer] //move the value forward
reversePointer -= 1; //decrease the pointer
}
inputData[reversePointer + 1] = selectElement //store the value at correct place
}
//Bubble Sort Algorithm
func bubbleSort(inputData: inout [Int]) {
var inputDataLength = inputData.count
while inputDataLength != 0 {
var newn = 0
for forwardPointer in 1...inputDataLength - 1 {
if (inputData[forwardPointer - 1] > inputData[forwardPointer]) {
let temp = inputData[forwardPointer - 1]
inputData[forwardPointer - 1] = inputData[forwardPointer]
// Bubble Sort in Java
public static void bubbleSort(int[] inputData) {
int inputDataLength = inputData.length;
while (inputDataLength != 0) {
int newn = 0;
for (int forwardPointer = 1; forwardPointer < inputData.length - 1; forwardPointer++) {
if(inputData[forwardPointer - 1] > inputData[forwardPointer]) {
final int temp = inputData[forwardPointer - 1];
inputData[forwardPointer - 1] = inputData[forwardPointer];
//Binary Search Algorithm
func binarySearch ( inputSortedData: [Int], searchElement: Int ) -> Int {
var minLeft = 0
var maxRight = inputSortedData.count - 1
while ( minLeft <= maxRight ) {
let middleElement = (minLeft + maxRight) / 2
if (searchElement == inputSortedData[middleElement]) { return middleElement + 1; }
if (searchElement < inputSortedData[middleElement]) { maxRight = middleElement - 1 }
if (searchElement > inputSortedData[middleElement]) { minLeft = middleElement + 1 }
public static int binarySearch(final int[] inputSortedData, final int searchElement) {
int minLeft = 0;
int maxRight = inputSortedData.length - 1;
while ( minLeft <= maxRight ) {
final int middleElement = (minLeft + maxRight) / 2;
if (searchElement == inputSortedData[middleElement]) { return middleElement + 1; }
if (searchElement < inputSortedData[middleElement]) { maxRight = middleElement - 1; }
if (searchElement > inputSortedData[middleElement]) { minLeft = middleElement + 1; }
}
return -1;
@SanjeevMohindra
SanjeevMohindra / Genesis Author Box Customisation
Last active January 31, 2018 12:50
A basic customisation to add social icons in Genesis Author Box
/**
* Author Box With Social Icons
*
* This function will add social icons to author box in genesis. Add this to your function.php
*
* @author MetaBlogue
* @license GPL-2.0+
* @link https://metablogue.com/genesis-add-social-media-icons-author-box/
*/
add_filter( 'genesis_author_box','custom_author_box', 10, 6);
@SanjeevMohindra
SanjeevMohindra / function.php
Created September 27, 2017 17:16
Remove ShortCode Plugin From WordPress
<?php
/**
* Remove ShortCode Plugin
*
* This function will remove the shortcode from getting diplayed. Add this to your function.php
*
* @author MetaBlogue
* @license GPL-2.0+
* @link https://metablogue.com/wordpress-remove-shortcode-plugin/
*/
@SanjeevMohindra
SanjeevMohindra / functions.php
Last active October 2, 2017 08:14
Remove ShortCode from WordPress while keep displaying the content
<?php
/**
* Remove ShortCode Plugin
*
* This function will remove the shortcode from getting diplayed while keep displaying the content.
* Add this to your function.php
*
* @author MetaBlogue
* @license GPL-2.0+
* @link https://metablogue.com/wordpress-remove-shortcode-plugin/
@SanjeevMohindra
SanjeevMohindra / functions.php
Last active October 4, 2017 11:37
Replace existing shortcakes with a new shortcode
<?php
/**
* Remove ShortCode Plugin
*
* This function will remove the shortcode from getting diplayed while keep displaying the content.
* Add this to your function.php
*
* @author MetaBlogue
* @license GPL-2.0+
* @link https://metablogue.com/wordpress-remove-shortcode-plugin/