Skip to content

Instantly share code, notes, and snippets.

View lnsp's full-sized avatar
👊

Lennart lnsp

👊
View GitHub Profile
@lnsp
lnsp / hashMap.js
Last active August 29, 2015 14:07
JavaScript hash map implementation
var JSL = JSL || {};
JSL.HashMap = function () {
"use strict";
var keys = [],
values = [];
function indexOf(key) {
var i = 0;
if (keys.indexOf !== undefined) {
return keys.indexOf(key);
}
@lnsp
lnsp / primeNumber.cpp
Created November 10, 2014 16:55
Tests if a given number is a prime number
bool isPrimeNumber(const int n) {
for (int i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
@lnsp
lnsp / palindrom.cpp
Last active August 29, 2015 14:09
Tests if a number is a palindrom
bool isPalindrom(const int n) {
int temp = n, reversed = 0;
while (temp != 0) {
int rem = temp % 10;
reversed = reversed * 10 + rem;
temp /= 10;
}
return reversed == n;
@lnsp
lnsp / collatz.py
Created November 25, 2014 20:04
Collatz algorithm implemented in Python 3.4
def collatz(x):
z = 0
while x != 1:
if x % 2 == 0:
x /= 2
else
x = x * 3 + 1
z += 1
return z
@lnsp
lnsp / Node.java
Created December 22, 2014 23:20
Simple tree structure
import java.util.ArrayList;
import java.util.List;
public class Node<T> {
private Node<T> parent;
private List<Node<T>> children;
private T data;
public Node(Node<T> parent) {
this(parent, null);
@lnsp
lnsp / HalloWelt.java
Last active August 29, 2015 14:17
Einstieg in die Programmierung - Folge 2
// package [Paketpfad]
package io.mooxmirror.javakurs2;
// öffentliche Klasse 'HalloWelt'
public class HalloWelt {
// Einstiegsmethode 'main(String[] args)', muss vorhanden sein!
public static void main(String[] args) {
// Gebe Text 'Hallo Welt!' aus!
System.out.println("Hallo Welt!");
@lnsp
lnsp / stack_structure.c
Last active August 29, 2015 14:17
A small Stack structure implementation
// A Stack structure implementation
// (c) 2015 mooxmirror
#include <stdlib.h>
#include <stdio.h>
#define STACK_TYPE int
#define STACK_TYPE_NULL 0
typedef struct stack stack;
@lnsp
lnsp / stack_structure2.c
Last active August 29, 2015 14:17
Reworked version of stack_structure.c
/*
A Stack structure implementation
(c) 2015 mooxmirror
*/
#include <stdlib.h>
#include <stdio.h>
#define STACK_TYPE int
#define STACK_TYPE_NULL NULL
@lnsp
lnsp / stack.c
Last active August 29, 2015 14:17
The best stack structure ever!
/*
A Stack structure implementation
(c) 2015 mooxmirror
*/
#include "stack.h"
Stack * Stack_create()
{
Stack * s = (Stack *) malloc(sizeof(Stack));
@lnsp
lnsp / Radix.java
Last active September 13, 2015 16:21
A simple radix sort implementation based on arrays
public static void sort(int[] a) {
int largestNumber = 0;
// find largest number
for (int n : a)
if (largestNumber < n) largestNumber = n;
// calculate needed iterations
final int maxIterations = (int) Math.log10(largestNumber) + 1;