Algorithm
直接插入排序
算法概述:
把前面的数组排好序,后面的元素插入到排好序的数组中。
实现思路:
把数组分为有序和无序两部分,分别用下标去指向(有序(j), 无序(i)),首先用tmp去存下无序的元素a[i],如果a[i]>= 有序数组最后的元素,则不做元素的改变;如果是小于关系且j>=0时,则会复制j处的元素给到j+1处。当跳出循环时,表示找到合适的位置或者遍历到数组头部了,就需要把tmp赋值到指定的位置。
代码实现:
#include <iostream>
using namespace std;
void StraightInsertionSort(int *a, int n)
{
for (int i = 1; i < n; i++)
{
int j;
int tmp = a[i];//给无序的元素找个家
for (j = i - 1; j >= 0 && tmp < a[j]; j--)
{
a[j+1] = a[j];//a[j]向后复制
}
a[j+1] = tmp;//把无序元素安放好
}
}
int main()
{
int a[5] = {4, 6, 8, 5, 9};
int nSize = sizeof(a)/sizeof(int);
StraightInsertionSort(a, nSize);
for (int i = 0; i < nSize; i++)
{
cout << a[i] << " ";
}
cout << endl;
return 0;
}
Review
What are some of the most basic things every programmer should know?
Bad architecture causes more problems than bad code.
坏的架构比坏的代码造成更多的问题.
You will spend more time thinking than coding.
相比于写代码,你将花费更多的时间在思考上.
The best programmers are always building things.
优秀的程序员经常建造事物.
There’s always a better way.
总有更好的方法.
Code reviews by your peers will make all of you better.
你同辈的代码审查将让你变得更好.
Fewer features for better code is always the right answer in the end.
最后更少的特性的代码往往是正确的答案.
If it’s not tested, it doesn’t work.
如果没有经过测试,它将不能工作.
Don’t reinvent the wheel, library code is there to help.
不要重复造轮子,库代码更有帮助.
Code that’s hard to understand is hard to maintain.Code that’s hard to maintain is next to useless.
难以理解的代码难以维护.难以维护的代码几乎可以说是无用的.
Always know how your business makes money, that determines who gets paid what.
清楚地知道你的生意如何创造金钱,这将决定谁会得到报酬.
If you want to feel important as a software developer, work at a tech company.
如果你想要感觉像软件开发工程师一样重要,去一家科技公司工作.
Tips
1.手机上将倒计时事项放到显眼位置,可以督促自己去行动起来
2.要记录周末时间的花费,弄清楚哪些事情是可以不去做的.