Skip to content

Instantly share code, notes, and snippets.

View kkdai's full-sized avatar

Evan Lin kkdai

View GitHub Profile
@kkdai
kkdai / PrintNLong.cpp
Last active January 4, 2016 14:19
Print Nst Long string of a series of string.
void PrintLongN(int N, const char *str)
{
//error check
if (N <=0 || *str == NULL)
{
assert(0);
printf("error! \n");
return;
}
@kkdai
kkdai / MemoryAlignment.cpp
Created January 26, 2014 15:24
Talking about alignment
int main(int argc, const char * argv[])
{
//#pragma pack(push)
#pragma pack(4)
struct align_test
{
char x; //1 byte
int y; //4 bytes
short int z; //2bytes
class BB
{
private:
int aa, bb;
public:
BB():aa(1),bb(5) //note: check about default value assign aa, bb depends on compiler. DON'T WRITE LIKE THAT
{
printf("Print out value aa = %d, bb=%d \n", aa, bb);
bb = aa;
printf("Print out value bb = %d \n", bb);
def logstn(strs, number)
while (number >0)
logest = strs.inject do |first, second|
(first.length > second.length)? first : second
end
puts logest
strs.delete_if {|x| x==logest}
number -= 1
end
end
#Ruby
puts " ----------------------- Basic moniplation --------------"
i=1
k="ss"
i=i+1
I=2
I=I+2
puts k
puts i
puts k+i.to_s #不可直接轉型~這是基本提供轉型與轉字串
class foo_class
{
foo_class()
private:
int a=0;
public:
int b=0,
void foo_fun1();
}
def quickSort_bigendian(input_arry)
index_i = 0
puts "Before sort"
puts input_arry.inspect
while (index_i < input_arry.size)
index_j = input_arry.size
index_j -= 1
while (index_j > index_i)
if ( input_arry[index_j] < input_arry[index_j-1] )
temp = input_arry[index_j-1]
def fibinacci(fib_number)
return fib_number <= 1 ? 1 : fibinacci(fib_number - 1) + fibinacci(fib_number - 2)
end
puts fibinacci(1) #output 1
puts fibinacci(3) #output 3
puts fibinacci(5) #output 8
#Ruby
def to_post_pre_fix(infix, isPost = true)
op_stack = [] #宣告成stack
return_str = "" #宣告成string
index_i=0
while (index_i < infix.size)
if (infix[index_i] == ")")
return_str << op_stack.pop #string operator add to back
elsif ("+-*/".include? infix[index_i])
isPost ? op_stack.push(infix[index_i]) : return_str << infix[index_i]
@kkdai
kkdai / About_Class_assign_size.cpp
Last active August 29, 2015 13:56
About class assign for public or private variable.
#include <iostream>
#include <stdio.h>
class aClass
{
private:
int a1=1;
public:
aClass():a1(2), a2(3)
{