51dev.com IT技术开发者社区

51dev.com 技术开发者社区

nohup 与 &

nohup 与 &

&的意思是在后台运行,什么意思呢? 意思是说,当你在执行./a.out&的时候,即使你用ctrlC, 那么a.out照样运行(因为对SIGINT信号免疫)。但是要注意,如果你直接关掉shell后,那么,a.out进程同样消失。可见,&的后台并不硬(因为对S...

退出shell 脚本

退出shell 脚本

#!/bin/bashexportTOP_PID=$$trap'exit1'TERMexit_script(){kill-sTERM$TOP_PID}echo"beforeexit":|exit_scriptecho"afterexit"EOF  执行结果为beforeexit...

python 散列表查找

python 散列表查找

classHashTable:def__init__(self,size):self.elem=[Noneforiinrange(size)]self.count=size#defhash(self,key):returnkey%self.count#definsert_hash(self,key)...

python 二叉排序树

python 二叉排序树

classBSTNode:def__init__(self,data,left=None,right=None):self.data=dataself.left=leftself.right=rightclassBinarySortTree:def__init__(self):self._root=...

python 斐波那契查找

python 斐波那契查找

deffibonacci_search(lis,key):#F=[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368]low=0high=len(lis)-1#k=0wh...

python 二分法查找

python 二分法查找

defbinary_search(lis,key):low=0high=len(lis)-1time=0whilelow<high:time+=1mid=int((low+high)/2)ifkey<lis[mid]:high=mid-1elifkey>lis[mid]:low=m...

python 插值查找

python 插值查找

defbinary_search(lis,key):low=0high=len(lis)-1time=0whilelow<high:time+=1#mid=low+int((high-low)*(key-lis[low])/(lis[high]-lis[low]))print("mid=%s,...

python 无序表查找

python 无序表查找

defsequential_search(lis,key):foriinrange(len(lis)):if(lis[i]==key):returnielse:returnFalseLIST=[1,5,8,123,22,54,7,99,300,222]result=sequential_search...

python 归并排序

python 归并排序

defmerge_sort(array):defmerge_arr(arr_l,arr_r):array=[]whilelen(arr_l)andlen(arr_r):ifarr_l[0]<=arr_r[0]:array.append(arr_l.pop(0))elifarr_l[0]>...

python 堆排序

python 堆排序

importcopydefheap_sort(hlist):defheap_adjust(parent):child=2*parent+1#leftchildwhilechild<len(heap):ifchild+1<len(heap):ifheap[child+1]>heap[...

python 基数排序

python 基数排序

defradix_sort(array):bucket,digit=[[]],0whilelen(bucket[0])!=len(array):bucket=[[],[],[],[],[],[],[],[],[],[]]foriinrange(len(array)):num=(array[i]//1...

python 快速排序

python 快速排序

defquick_sort(qlist):ifqlist==[]:return[]else:qfirst=qlist[0]qless=quick_sort([lforlinqlist[1:]ifl<qfirst])qmore=quick_sort([mforminqlist[1:]ifm>...

python 选择排序

python 选择排序

defselect_sort(slist):foriinrange(len(slist)):x=iforjinrange(i,len(slist)):ifslist[j]<slist[x]:x=jslist[i],slist[x]=slist[x],slist[i]returnslistsli...

python 冒泡排序

python 冒泡排序

defbubble_sort(blist):count=len(blist)foriinrange(0,count):forjinrange(i+1,count):ifblist[i]>blist[j]:blist[i],blist[j]=blist[j],blist[i]returnblis...

python排序(插入排序)  从小到大顺序

python排序(插入排序) 从小到大顺序

definsert_sort(ilist):foriinrange(len(ilist)):forjinrange(i):ifilist[i]<ilist[j]:ilist.insert(j,ilist.pop(i))breakreturnilistilist=insert_sort([4,5...