Skip to content

Instantly share code, notes, and snippets.

View ecigar13's full-sized avatar
💭
Doing what I need to do.

Keith Nguyen ecigar13

💭
Doing what I need to do.
View GitHub Profile
@kean
kean / CtCI-6h-problem-4.9.markdown
Last active February 24, 2023 14:53
CtCI 6h Edition, Problem 4.9: BST Sequences.

Problem 4.9. BST Sequences: A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.

Solution.

Let's start with an example.

    4
   / \
  2   5 
@migf1
migf1 / s_new_from_stdin.c
Last active July 16, 2021 02:03
Read portably a string of arbitrary length from the console in C ( ANSI C89 / ISO C90 ).
#include <stdio.h> /* getchar() */
#include <stdlib.h> /* malloc(), realloc() */
#include <string.h> /* memcpy() */
/* -----------------------------------------------
* Create a new string (NUL-terminated array of chars) by reading the stdin.
* Return the newly created string, or NULL on error.
* Args:
* int beExact: If 0 (false), then the size of the created string will
* be an exact multiple of the internally used alloc-ahead
@btmills
btmills / ufgets.c
Last active December 13, 2022 01:44
Unlimited fgets() - read input from the console with automatic buffer sizing.
#include <stdio.h>
#include <stdlib.h>
/*
* Similar to fgets(), but handles automatic reallocation of the buffer.
* Only parameter is the input stream.
* Return value is a string. Don't forget to free it.
*/
char* ufgets(FILE* stream)
{