Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
krysseltillada / Rreverse.c
Created January 17, 2016 12:51
ex 4-13 (c the programming language 2 ed) reverse recursion
#include <stdio.h>
#include <string.h>
void reverse (char str[])
{
static char temp[100];
static int i = 1;
static int first = 0;
@krysseltillada
krysseltillada / calc.c
Created January 15, 2016 15:22
calc polish notation (ex 4-3 --> 4-10 c the programming language 2nd ed)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAXOP 100
#define NUMBER '0'
#define MAXBUFFER 1000
#define TRUE 1
#define FALSE 0
@krysseltillada
krysseltillada / itob.c
Created January 11, 2016 18:53
ex 3-5 (the c programming language 2 ed)
#include <stdio.h>
#include <string.h>
void copy (char to[], char from[]) {
int i = 0;
for (; (to[i] = from[i]) != '\0'; ++i );
}
char intChar (int n) {
return (n >= 0 && n <= 9) ? n + 48 : ' ';
@krysseltillada
krysseltillada / expand.c
Created January 11, 2016 15:02
ex 3-3 (the c programming language)
#include <stdio.h>
void expand (char s1[], char s2[])
{
int i = 0, n, x = 0;
if (s1[i] >= 'a' && s1[i + 1] == '-' && s1[i + 2] <= 'z') {
if (s1[i + 3] == '-' && (s1[i + 2] >= s1[i] && s1[i + 2] <= s1[i + 4]) && s1[i + 4] <= 'z') {
for (n = s1[i]; n <= s1[i + 4]; ++n, ++x)
@krysseltillada
krysseltillada / squeeze.c
Created January 9, 2016 13:54
exercise 2-4 (the c programming language 2nd ed)
#include <stdio.h>
size_t getlen (char arr[])
{
int sz = 0;
for (; arr[sz] != '\0'; ++sz);
return sz;
}
void printStr (char arr[])
@krysseltillada
krysseltillada / htoi.c
Created January 8, 2016 18:58
exercise 2-3 (the c programming language 2nd ed) hexadecimal constant strings to decimal
#include <stdio.h>
int getLength (char s[]) {
int sz = 0;
for (; s[sz] != '\0'; ++sz);
return sz;
}
int pow (int c, int n) {
int i = 0, v = 1;
@krysseltillada
krysseltillada / synchecker.c
Created January 7, 2016 15:22
syntax checker (ex 1 -24 ) (the c programming language book 2nd ed)
#include <stdio.h>
void scanComment (int);
void scanBraces ();
void scanParen ();
void scanDquote ();
void scanSquote ();
int main ()
{
@krysseltillada
krysseltillada / RTTI.cpp
Created December 21, 2015 16:06
Run Time Type Identification (RTTI)
#include <iostream>
#include <vector>
#include <typeinfo>
class Base {
public:
virtual ~Base () { } /// we need to defined this as virtual for dynamic type destructors
};
@krysseltillada
krysseltillada / EngineHandler.cpp
Created December 17, 2015 16:35
exception handling
#include "EngineHandler.hpp"
/*
implementation file
*/
namespace EngineHandler {
MainEngineHandler::MainEngineHandler ( const std::string &errMsg, const int &errCode ) try : /// initializes a constructor with a try block and catch block handler for exception purposes
errorMsg ( errMsg ), errorCode ( errCode ) { } catch ( std::runtime_error &e ) {
std::cerr << e.what () << std::endl;
@krysseltillada
krysseltillada / algorithms.py
Last active November 12, 2015 14:43
python (Bubble_sort, Binary_search) implementation
class Algorithms: # wrap them as a class
def __init__ (self): # default method instantiation
return
def BubbleSort (self, param, sortMethod): # bubblesort implementation
i = 1
temp = 0
if (sortMethod == "ascending"):
for i in range(len(param)):