private void QuickSort( int[] a, int left, int right ) { if( a == null ) return; int i = left; int j = right; int pivot = a[( left + right ) / 2]; while( i <= j ) { while( a[i] < pivot ) i++; while( a[j] > pivot ) j--; if( i <= j ) { int tmp = a[i]; a[i++] = a[j]; a[j--] = tmp; } } if( j > left ) { QuickSort( a, left, j ); } if( i < right ) { QuickSort( a, i, right ); } }
An innovative, experienced solutions architect with strong focus on public cloud architecture, solution design and leading technical team. Zhen has 15 years experience designing and implementing a wide spectrum of enterprise level solutions. In the last 4 years, he is committed to evangelising Azure, DevOps and Scrum. His recent focus are enterprise digitisation, cloud governance, reference architecture, IoT, Big Data, Microservices, AWS.
Monday, November 16, 2009
c# Quick Sort Algorithm Implementation
c# insert sort algorithm implementation
private void insert_sort( int[] s )
{
for( int k = 1; k < s.Length ; k++ )
{
int value = s[k];
for( int i = 0; i <= k - 1; i++ )
{
if( value < s[i] )
{
for( int j = k - 1; j >= i; j-- )
s[j + 1] = s[j];
s[i] = value;
break;
}
}
}
}
Saturday, October 31, 2009
键盘上的符号发音
~
tilde (sounds like til-da); be prepared to explain to computer-illiterate people saying "you know, the wave-shaped thingy"
!
exclamation; commonly read as bang in case of #!/bin/sh
@
at
#
pound; but commonly read as shee in case of #!/bin/sh, not sure why
$
dollar
%
percent
^
caret; not many people know this word so be prepared to say "no, not carrot; it's the character above 6, an arrow pointing up"
&
ampersand
*
star; some read asterisk
(
opening parenthesis (some may shorten it saying paren)
)
closing parenthesis
_
underscore; once I heard people say underbar
+
plus
-
minus; as symbol before arguments in commands, some people including me read dash, easier to say one syllable
=
equals
`
backtick or backquote
{
opening brace
}
closing brace
[
opening bracket
]
closing bracket
|
pipe or vertical bar
\
backslash; be prepared to explain to some computer-illiterate people
:
colon
;
semicolon
"
double quote
'
single quote
<
less than; some may read left angle bracket
>
greater than
,
comma
.
dot; period if in English text
?
question mark
/
slash or forward slash; some computer-illiterate people may be confused about / and \
space
(), [] and {}
may also be called brackets in general. In that case, they specifically call [] square brackets and {} curly brackets. I never like this. Open and Closing may also be called left and right.
Saturday, October 24, 2009
Thursday, October 8, 2009
c# copy excel data and paste into datagridview table
This post is about managing the memory data object after ctrl+c is used in Excel. You will learn how data are organised in memory and should be able to apply it anywhere. The code example tries to read the data in DataObject out and paste it in datagridview.
DataObject o = (DataObject) Clipboard.GetDataObject();
if (o.GetDataPresent(DataFormats.Text))
{
int rowOfInterest = DataGridView.CurrentCell.RowIndex;
string[] selectedRows = Regex.Split(o.GetData(DataFormats.Text).ToString( ).TrimEnd( "\r\n".ToCharArray() ), "\r\n");
if (selectedRows == null || selectedRows.Length == 0)
return;
foreach (string row in selectedRows)
{
if (rowOfInterest >= DataGridView.Rows.Count)
break;
try
{
string[] data = Regex.Split(row, "\t");
int col = DataGridView.CurrentCell.ColumnIndex;
foreach (string ob in data)
{
if (col >= DataGridView.Columns.Count)
break;
if (ob!=null)
DataGridView[col, rowOfInterest].Value = Convert.ChangeType( ob, DataGridView[col,rowOfInterest].ValueType );
col++;
}
}
catch (Exception enterException)
{
//do something here
}
rowOfInterest++;
}
}