add gitignore
This commit is contained in:
@@ -1,185 +0,0 @@
|
||||
// C Standard Library Cheatsheet Template
|
||||
// A clean, two-column layout for quick reference during coding interviews.
|
||||
// Created with Typst.
|
||||
|
||||
// ================= DOCUMENT SETUP =================
|
||||
#set document(title: "C Standard Library Reference", author: "David Gao")
|
||||
|
||||
#let base-text-size = 9pt
|
||||
|
||||
#set text(font: "Arial", size: base-text-size)
|
||||
#show raw: set text(size: base-text-size)
|
||||
|
||||
#set page(paper: "a4", margin: (top: 0.75in, bottom: 0.75in, left: 0.5in, right: 0.5in))
|
||||
|
||||
// Define colors for styling to make sections stand out.
|
||||
#let primary_color = navy
|
||||
#let secondary_color = luma(230)
|
||||
|
||||
// ================= CUSTOM SHOW RULE (The Cheatsheet Engine) =================
|
||||
#let entry(signature, description, code_lang: "cpp") = {
|
||||
grid.cell[
|
||||
#rect(width: 100%, inset: (x: 4pt, y: 3pt), fill: luma(240), radius: 2pt, [#raw(signature, lang: code_lang)])
|
||||
]
|
||||
grid.cell[
|
||||
#description
|
||||
]
|
||||
}
|
||||
|
||||
// This function formats a larger code snippet for algorithms/data structures.
|
||||
#let code_snippet(title, code) = {
|
||||
pad(bottom: 4pt, text(weight: "bold", title))
|
||||
rect(
|
||||
width: 100%,
|
||||
inset: 8pt,
|
||||
fill: luma(240),
|
||||
radius: 3pt,
|
||||
code
|
||||
)
|
||||
v(1em)
|
||||
}
|
||||
|
||||
// ================= HEADER FUNCTION =================
|
||||
#let section_header(title) = {
|
||||
block(width: 100%, fill: primary_color, inset: 6pt, radius: 3pt, text(white, weight: "bold", title))
|
||||
v(8pt)
|
||||
}
|
||||
|
||||
// ================= CHEATSHEET CONTENT =================
|
||||
|
||||
// Main Title
|
||||
#align(center)[
|
||||
#text(size: 20pt, weight: "bold", "C Standard Library Reference")
|
||||
#line(length: 100%, stroke: 1pt)
|
||||
#v(1em)
|
||||
]
|
||||
|
||||
#section_header("stdio.h — Standard Input/Output")
|
||||
|
||||
#grid(
|
||||
columns: (auto, 1fr),
|
||||
column-gutter: 8pt,
|
||||
row-gutter: 6pt,
|
||||
)[
|
||||
#entry(
|
||||
"int printf(const char* format, ...);",
|
||||
[Prints formatted output to `stdout`. Common specifiers: `%d` (int), `%f` (float/double), `%c` (char), `%s` (string), `%p` (pointer).],
|
||||
)
|
||||
#entry(
|
||||
"int sprintf(char* str, const char* format, ...);",
|
||||
[Prints formatted output to a string `str`.]
|
||||
)
|
||||
#entry(
|
||||
"int scanf(const char* format, ...);",
|
||||
[Reads formatted input from `stdin`.]
|
||||
)
|
||||
#entry(
|
||||
"int getchar(void);",
|
||||
[Reads the next character from `stdin`.]
|
||||
)
|
||||
#entry(
|
||||
"int putchar(int ch);",
|
||||
[Writes a character `ch` to `stdout`.]
|
||||
)
|
||||
]
|
||||
|
||||
#v(1.5em) // Vertical space between sections
|
||||
|
||||
// --- stdlib.h Section ---
|
||||
#section_header("stdlib.h — Memory, Conversions, Utilities")
|
||||
|
||||
#grid(
|
||||
columns: (auto, 1fr),
|
||||
column-gutter: 8pt,
|
||||
row-gutter: 6pt,
|
||||
)[
|
||||
#entry(
|
||||
"void* malloc(size_t size);",
|
||||
"Allocates `size` bytes of uninitialized memory. Returns a void pointer to the allocated space.",
|
||||
)
|
||||
#entry(
|
||||
"void* calloc(size_t nmemb, size_t size);",
|
||||
"Allocates memory for an array of `nmemb` elements of `size` bytes each and initializes all bits to zero.",
|
||||
)
|
||||
#entry(
|
||||
"void* realloc(void* ptr, size_t size);",
|
||||
"Resizes the memory block pointed to by `ptr` to `size` bytes. The content will be unchanged up to the minimum of the old and new sizes.",
|
||||
)
|
||||
#entry(
|
||||
"void free(void* ptr);",
|
||||
"Deallocates a block of memory previously allocated by `malloc`, `calloc`, or `realloc`.",
|
||||
)
|
||||
#entry("int atoi(const char* str);", "Converts the initial portion of the string `str` to an `int`.")
|
||||
#entry(
|
||||
"long int strtol(const char* str, char** endptr, int base);",
|
||||
"Converts string `str` to a `long int`. `endptr` can be used to see where conversion stopped. `base` is the number base (e.g., 10).",
|
||||
)
|
||||
#entry(
|
||||
"void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));",
|
||||
"Sorts an array. `compar` is a pointer to a function that compares two elements.",
|
||||
)
|
||||
#entry("int rand(void);", "Returns a pseudo-random integer between 0 and `RAND_MAX`.")
|
||||
#entry("void srand(unsigned int seed);", "Seeds the pseudo-random number generator used by `rand()`.")
|
||||
#entry("void exit(int status);", "Causes normal program termination. `EXIT_SUCCESS` or `EXIT_FAILURE`.")
|
||||
]
|
||||
|
||||
#v(1.5em)
|
||||
|
||||
// --- string.h Section ---
|
||||
#section_header("string.h — String Manipulation")
|
||||
|
||||
#grid(
|
||||
columns: (auto, 1fr),
|
||||
column-gutter: 8pt,
|
||||
row-gutter: 6pt,
|
||||
)[
|
||||
#entry(
|
||||
"size_t strlen(const char* s);",
|
||||
"Calculates the length of string `s`, excluding the terminating null byte (`'\\0'`).",
|
||||
)
|
||||
#entry(
|
||||
"char* strcpy(char* dest, const char* src);",
|
||||
"Copies the string `src` to `dest`. *Unsafe*, does not check buffer size.",
|
||||
)
|
||||
#entry(
|
||||
"char* strncpy(char* dest, const char* src, size_t n);",
|
||||
"Copies up to `n` characters from `src` to `dest`. May not be null-terminated if `src` is too long.",
|
||||
)
|
||||
#entry(
|
||||
"int strcmp(const char* s1, const char* s2);",
|
||||
"Compares two strings. Returns < 0 if s1 < s2, 0 if s1 == s2, > 0 if s1 > s2.",
|
||||
)
|
||||
#entry(
|
||||
"char* strchr(const char* s, int c);",
|
||||
"Returns a pointer to the first occurrence of character `c` in string `s`, or `NULL` if not found.",
|
||||
)
|
||||
#entry(
|
||||
"char* strstr(const char* haystack, const char* needle);",
|
||||
"Finds the first occurrence of the substring `needle` in the string `haystack`.",
|
||||
)
|
||||
#entry(
|
||||
"void* memset(void* s, int c, size_t n);",
|
||||
"Fills the first `n` bytes of the memory area pointed to by `s` with the constant byte `c`.",
|
||||
)
|
||||
#entry(
|
||||
"void* memcpy(void* dest, const void* src, size_t n);",
|
||||
"Copies `n` bytes from memory area `src` to memory area `dest`.",
|
||||
)
|
||||
]
|
||||
|
||||
#section_header("Common Algorithms & Data Structures")
|
||||
|
||||
#code_snippet(
|
||||
"Binary Search (Iterative)",
|
||||
```cpp
|
||||
int binary_search(int arr[], int l, int r, int x) {
|
||||
while (l <= r) {
|
||||
int m = l + (r - l) / 2;
|
||||
if (arr[m] == x) return m; // Check if x is present at mid
|
||||
if (arr[m] < x) l = m + 1; // If x greater, ignore left half
|
||||
else r = m - 1; // If x is smaller, ignore right half
|
||||
}
|
||||
return -1; // if we reach here, then element was not present
|
||||
}
|
||||
```
|
||||
)
|
||||
1
leetcodecheatsheet/.gitignore
vendored
Normal file
1
leetcodecheatsheet/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.pdf
|
||||
Reference in New Issue
Block a user