Skip to content

Instantly share code, notes, and snippets.

View kkdai's full-sized avatar

Evan Lin kkdai

View GitHub Profile
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)
{
@kkdai
kkdai / MultipleIneritance.cpp
Last active August 29, 2015 13:56
Regular problem which comes from multiple inheritance
#include <iostream>
#include <stdio.h>
class L
{
private:
int a1=1;
public:
L():a1(2), a2(a1) //Don't use like this, a2 result depends on compiler
{}
@kkdai
kkdai / Vincent_lambda.cs
Created February 13, 2014 12:39
Try to converse it back to delegate or .Net 2.0
Mapper.CreateMap<DTOObject, MainObject>().ForMember(
d => d.TopObject,
mc => mc.MapFrom(s => new SubObject(){
SubPropText = s.TopText,
SubPropFont = s.TopFont
}
));
//-->
@kkdai
kkdai / lambda.cs
Created February 14, 2014 00:50
Some sample about lambda
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{