Basic Concept
Processes ManagementA process, in simple terms, is an instance of running program. Whenever you issue a command in Linux, it creates or start a process. Processes TypesWhen you issue a command (a process), there are two ways you can run it. Foreground Process Background Process The simplest way to start a background process is to add an ampersand (&) at the end of the command. Checking Running ProcessesIt is easy to see your own processes by using the ps command. In addition, you...
basic operations
FileListing File ls- listing files in current directory ls -l will help you get more information of the files To list the invisible files, specify the -a option to ls − Copying FilesTo make a copy of a file use the cp command. The basic syntax of the command is − 1$ cp source_file destination_file Renaming FilesTo change the name of a file, use the mv command. Following is the basic syntax − 1$ mv old_file new_file The mv command will move the existing file completely into the new file....
Shell & Shell scripts
IntroductionUsers communicate with the kernel through a program known as the shell. The shell is a command line interpreter; it translates commands entered by the user and converts them into a language that is understood by the kernel. Shell is an environment in which we can run our commands, programs, and shell scripts. A shell provides an interface to your Linux System. It gathers your inputs and executes programs based on that input. The shell is, after all, a real programming language,...
JavaScript
IntroductionJavaScript can change HTML content. Firstly, we have to get the element, one of many JavaScript HTML method is getElementById() The example below get the element id=”demo”, and changes the element content to “Hello JavaScript!” 123<p id="demo">JavaScript can change HTML content.</p><button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click...
PSO
算法思想该算法,通过追随当前搜索到的最优值来寻找全局最优 试着想一下一群鸟在寻找食物,在这个区域中只有一只虫子,所有的鸟都不知道它在哪。但是它们知道自己的当前位置距离食物有多远,它们通过相互联系,知道离食物最近的鸟的位置,同时各只鸟在位置不停变化时候离食物的距离也不断变化。 现在把鸟抽象为粒子。 粒子仅具有两个属性:速度V和位置X。粒子i在N维空间的位置表示为矢量Xi=(x1,x2,…,xN),飞行速度表示为矢量Vi=(v1,v2,…,vN)。 它们知道自己到目前为止发现的最好位置(pbest)和现在的位置Xi 每个粒子还知道到目前为止整个群体中所有粒子发现的最好位置(gbest)(gbest是pbest中的最好值) 最终,粒子就是通过自己的经验和同伴中最好的经验来决定下一步的运动。 粒子速度和位置的更新 该公式是从上面公式中的一个改进,增加了一个惯性因子。 这两条公式称为标准的PSO算法。 算法实现举例y=-x*(x-2)...
Merge Sort
原地归并排序算法思想有这样的一个问题,要使得两个有序的数组,合并成一个有序的数组。归并排序就是以这样的想法递归地对一个无序的数组进行排序。 先来思考:如何才能能将两个有序的数组,合并成一个有序的数组。 因为两个数组是有序的,所以使用指针指向这两个数组的首元,一一进行比较。 较小的一方放在新数组的前面,并且往后移动指针。 如果,指针越过了数组范围,那么就把另一个数组的所有元素放到新数组的最后面。 算法描述 格外开通一个辅助数组aux[] 1234567891011121314151617181920212223242526272829303132333435363738394041424344int less_(int a, int b){ if (a < b) return 1; else return 0;}void merge(int a[], int lo, int mid, int hi){ int i = lo, j = mid + 1; int aux[maxsize];...
数组名的传递
1234567891011121314void t(int* a){ cout<<sizeof(a)<<endl;//8}int main(int argc, char const *argv[]){ int a[5]={1,2,3,4,5}; t(a); cout<<sizeof(a)<<endl;//20 return 0;} 很明显cout的那么两行,是同样的,但为什么输出一个是8,一个20呢?我们已知64位的gcc中一个pointer是由8bytes的。所以,传递数组名(地址)给函数,sizeof计算的是a的指针大小,不是整个数组的大小。 此技巧仅适用于数组,不适用于指针: 1sizeof(b) / sizeof(b[0])
The reference datatype
Reference datatypes**The reference variables are just like the pointers in C. ** Reference datatypes in java are those which contains reference/address of dynamically created objects. These are not predefined like primitive data types. Following are the reference types in Java. class types − This reference type points to an object of a class. array types − This reference type points to an array. interface types − This reference type points to an object of a class which implements an...
Hiding of the reference
Today, I made a serious error, which is allocating the memory of reference variable repeatedly. However, if I did it, the complier will throw a error. Why did I create two references that have the same names but the complier didn’t throw the error? The reason is that I create a reference outside the method and the other reference that has the same name was created inside the method. This may be fatal. Because the first reference would be hided while the program was running in the...
整数和小数
int & float 前提 我们已经知道int是整形(只能输出整数),float是浮点型(能输出小数) 仍需知道一点 在两个int类型进行运算的时候,C默认会把计算结果变成int。那么: 1print("%f", 1/2); //0.000000 为什么结果是小数,但又是0呢? 因为先算1/2=0,再将int类型的0,变成float 1printf("%f\n", 1.0/2); //0.500000 这里的1.0是double型,在计算前先把2变成double,再计算。那么就是得到double型的值0.500000。 总结计算的时候要留意数字的类型,防止结果的出乎意料
