Skip to content

Instantly share code, notes, and snippets.

View rcanepa's full-sized avatar

Renzo Canepa rcanepa

  • Santiago, Chile
View GitHub Profile
@rcanepa
rcanepa / gist:31a2e2e987c8b2c2f665
Last active August 29, 2015 14:15
C++ Insertion Sort
#include <iostream>
#include <stdlib.h>
void insertion_sort(int *list, int lenght);
int main(int argc, char const *argv[])
{
int list_length = 30;
int list[list_length];
srand(time(NULL));
@rcanepa
rcanepa / gist:4a5e563a0e82780c8459
Last active August 29, 2015 14:15
C++ Selection Sort
#include <iostream>
#include <stdlib.h>
void selection_sort(int *list, int list_length);
int main()
{
int list_length = 30;
int list[list_length];
@rcanepa
rcanepa / gist:236e1af93969e665268f
Last active August 29, 2015 14:15
Python Insertion Sort
def insertion_sort(arr):
for idx, number in enumerate(arr):
current = idx
previous = idx - 1
if idx > 0:
while arr[current] < arr[previous] and (previous >= 0):
temp = arr[current]
arr[current] = arr[previous]
arr[previous] = temp
current = previous
@rcanepa
rcanepa / gist:5505446c290572a86bec
Last active August 29, 2015 14:15
Python Merge Sort
import random
def merge(left_arr, right_arr):
"""
Receives two ordered lists and returns a ordered
list created from the merge of the other two.
:param left_arr: ordered list
:param right_arr: ordered list
:return: ordered list created from the merge of left_arr and right_arr
@rcanepa
rcanepa / gist:fc29c00c4185c4a13b54
Last active June 9, 2021 21:07
C++ Binary Search (iterative and recursive)
#include <iostream>
#include <stdlib.h>
#include <time.h>
int binary_search(int list[], int length, int to_be_found);
int recursive_binary_search(int list[], int to_be_found, int p, int r);
int main()
{