希尔算法自己编了一个,循环很多,很不美观,不过运行正确: c语言实现: #include <stdio.h> #include <stdlib.h> #define LEN 20 int main() { int d,i,j,k; int arr[]={20,19,16,17,11,12,13,18,14,15,10,9,8,7,6,5,4,3,2,1}; int key; for(d=LEN/2;d>0;d--) for(i=0;i<d;i++) for(j=i+d;…
希尔排序: 伪代码: input: an array a of length n with array elements numbered 0 to n − 1 inc ← round(n/2) while inc > 0 do: for i = inc .. n − 1 do: temp ← a[i] j ← i while j ≥ inc and a[j − inc] > temp do: a[j] ← a[j − inc] j ← j − inc a[j] ← temp inc ← ro…
请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:ax² + bx + c = 0的两个解. #!/usr/bin/env python # -*- coding: utf-8 -*- import math def quadratic(a,b,c): if a == 0: raise TypeError('a不能为0') if not isinstance(a,(int,float)) or not isinstance(b,(int,float)) or n…