President Obama says the U.S.tax code is cheating the United States out of good-paying jobs and badly needed funds.
VOA: standard.2009.05.04
All right so-- yeah, how do I get to the code for that? That's interesting.
噢,我是怎么写出这个的代码,这件事儿挺有意思的。
Again, I want you to start seeing how to map the characteristics of the code- the characteristics of the algorithm, let's not call it the code-- to the complexity.
是算法中的那些特性,我们还是别说代码了,转化为复杂度-,我一会儿还会再讲点儿这个的,但是我们再看一个例子。
So let's take a look then at somewhere where this is actually a useful thing to know so this is compare1.c. So, in compare1.c I've stripped out the comments in my version but in your version you do have comments for reference and it's actually pretty self-explanatory if you just read through the code.
那么再然我们看一看,一些有用的东西,这是compare1。c,所以在compare1。c中,在我的版本中,我吧注释去掉了,但是在你们的版本中是有注释的,这是相当容易理解的,如果你通读这段代码。
So let's look at the second example, all right, I keep doing that -- this piece of code from here to here gives me a way of now creating a hash table of size 256.
所以让我们来看一下第二个例子,好的,我继续做那件事,这段代码中从这里到这里,是创建一个大小为256的哈希表。
to do sqrt, or square root-- no, I'm going to square root use sqrt, that's the name I'm using here-- square root a hundred different places in some piece of code. Without function, I'd have to copy that piece of code everywhere.
让我做一下准备,想象一下我要调用sqrt或者-,不,我会调用sqrt函数,这是我在这里用的名字,我得把这段代码到处复制。
But let's look a little more carefully at the code for binary search-- for search 1.
二分搜索算法的代码,那么search,1,这个方法的。
OK.Let's look at the code-- actually, let's test this out first before we do it.
因此我已经添加了,就像Guttag教授做的那样-啊,应该这么说。
So in other words, if you terminate these lines early, if you terminate the four loop early, if you terminate an if condition early with that semicolon, the code may very well work; and this is a common source -- of frustration and conundrum because you don't -- because your code looks right and yet it's misbehaving, but that semicolon means stop looking for subsequent lines of related code.
换句话说,如果你用分号过早的终止了这些代码行,如果你过早地终止了那个for循环,如果如此,一个if条件,代码可能可以运行,这就是,挫折和问题产生的源头,因为你没有-,因为你的代码看起来是正确的,但是运行是错误的,那个分号的意思是,停止寻找后面相关的代码。
应用推荐