Skip to content

Instantly share code, notes, and snippets.

@PsySc0rpi0n
PsySc0rpi0n / matrix.c
Last active June 5, 2016 10:05
A matrix being rastered by a number
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CLEAR_INPUT while (getchar () != '\n') /*void*/
#define CLEAR_SCREEN printf ("\x1b[3;J\x1b[H\x1b[2J")
int* create_matrix(int h, int w){
int* tmp_mtx = NULL;
@PsySc0rpi0n
PsySc0rpi0n / recursion.c
Last active May 30, 2016 21:49
recursive functions
int GetNodeHeight ( bstNode *node ) {
int height_left = 0;
int height_right = 0;
if( node->left ) height_left = GetNodeHeight ( node->left );
if( node->right ) height_right = GetNodeHeight ( node->right );
return height_right > height_left ? ++height_right : ++height_left;
}
@PsySc0rpi0n
PsySc0rpi0n / avl_tree.c
Last active June 7, 2016 13:37
AVL Binary Tree
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct bstNode{
int data;
struct bstNode* left;
struct bstNode* right;
}bstNode;
@PsySc0rpi0n
PsySc0rpi0n / sizeof.c
Created May 29, 2016 10:07
Discussing a possible issue
int buffer[20];
int *pbuffer = buffer;
for(int i=0; i<sizeof(buffer); i++) {
*(pbuffer++) = 0;
}
@PsySc0rpi0n
PsySc0rpi0n / secFree.c
Created May 29, 2016 01:12
A secure way to free memory
void SecFree (void** memRef) {
if (memRef != NULL && *memRef != NULL){
free (*memRef);
*memRef = NULL;
}
}
//usage
secFree ((void** ) &memRef);
@PsySc0rpi0n
PsySc0rpi0n / bst.c
Last active May 28, 2016 19:18
binary search tree
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct bstNode {
int data;
struct bstNode* left;
struct bstNode* right;
}bstNode;
@PsySc0rpi0n
PsySc0rpi0n / tabuleiro.c
Last active May 28, 2016 17:45
Someone's code
#include <stdio.h>
char desenha_tabuleiro(int tam_linhas, int tam_colunas){
char tabuleiro[tam_linhas][tam_colunas];
int j,i;
//PREENCHE TABULEIRO COM *
for (j = 0; j < tam_linhas; j++)
for (i = 0; i < tam_colunas; i++)