kokozeng / datastructure Goto Github PK
View Code? Open in Web Editor NEW数据结构与算法的学习 base python/c++
数据结构与算法的学习 base python/c++
4.11 冒泡排序、梳理华为机试和python知识点、看绝缘子机器学习处理方法
整理个人工作流在装了啥,更新repo
4.12 选择排序、插入排序、希尔排序、快速排序
4.14 归并排序,算法面试通关[优先队列] 本科毕设交流
4.15 二分查找,华为真题部分回顾 树
4.9 《大话数据结构》[86/439] 数据结构与算法[19/44] 算法面试通关40讲 [0/62] 华为机试[13/108]
4.10《大话数据结构》[86/439] 数据结构与算法[19/44] 算法面试通关40讲 [6/62] 华为机试[13/108]
(warning:链表交换相邻元素的题还没做)
4.11《大话数据结构》[86/439] 数据结构与算法[21/44] 算法面试通关40讲 [9/62] 华为机试[13/108]
4.12《大话数据结构》[86/439] 数据结构与算法[30/44] 算法面试通关40讲 [9/62] 华为机试[13/108]
4.13《大话数据结构》[86/439] 数据结构与算法[30/44] 算法面试通关40讲 [9/62] 华为机试[21/108]
4.14《大话数据结构》[86/439] 数据结构与算法[33/44] 算法面试通关40讲 [12/62] 华为机试[21/108]
4.15《大话数据结构》[86/439] 数据结构与算法[36/44] 算法面试通关40讲 [12/62] 华为机试[21/108]
def fab(max):
n, a, b = 0, 0, 1
while n < max:
yield b # 使用 yield
#print (b)
a, b = b, a + b
n = n + 1
for n in fab(6):
print (n, end = ' ')
1 1 2 3 5 8
a, b = b, a + b 这个操作是否是并行的?
Python continue 语句跳出本次循环,而break跳出整个循环。
continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。
continue语句用在while和for循环中.
# 递归方式
def binary_search(alist, first, last, item):
mid = (first + last)//2
# 递归的退出条件
if alist[mid] == item :
print(mid)
return mid
if alist[mid] > item:
binary_search(alist, first, mid - 1, item)
else:
binary_search(alist, mid + 1, last, item)
if __name__ == "__main__":
alist=[12,34,56,45,23,523,64,123,5346,4,30]
# 因为查找是针对有序的顺序表
alist.sort()
print(alist)
pos = binary_search(alist, 0, len(alist)-1, 123)
# 为什么输出是none return出问题了吗?
print(pos)
[4, 12, 23, 30, 34, 45, 56, 64, 123, 523, 5346]
8
None
为什么输出是None
催更催更,这个repo好久没更新了!
# 快速排序
def quick_sort(alist, first, last):
if first >= last:
return
min_value = alist[first]
low = first
high = last
while high > low:
while low < high and alist[high] >= min_value:
high -= 1
alist[low] = alist[high]
while low < high and alist[low] < min_value:
low +=1
alist[high] = alist[low]
alist[low] = min_value
quick_sort(alist, first, low-1)
quick_sort(alist, low+1, last)
if __name__ == "__main__":
alist=[12,34,56,45,23,523,64,123,5346,4,30]
quick_sort(alist, 0, len(alist)-1)
print(alist)
[4, 12, 23, 30, 34, 45, 56, 64, 123, 523, 5346]
但是倒数第二行如果是
alist = quick_sort(alist, 0, len(alist)-1)
输出就变成None
是因为函数是对alist直接操作,没有return吗?
s='abc00000 12345678 90000000'
s = s.split()
print("将字符串按空格分割:", s)
s.sort()
print("字符串升序:", s)
s.sort(reverse=True)
print("字符串降序:", s)
# 获取列表的第二个元素
def takeSecond(elem):
return elem[0]
# 指定第二个元素排序
'''没看懂这里是什么操作, 不是takeSecond(s)吗?还有这个key在排什么序也不懂'''
s.sort(key=takeSecond)
# 输出类别
print ('排序列表:', s)
将字符串按空格分割: ['abc00000', '12345678', '90000000']
字符串升序: ['12345678', '90000000', 'abc00000']
字符串降序: ['abc00000', '90000000', '12345678']
排序列表: ['12345678', '90000000', 'abc00000']
实例
>>>a = 111
>>> isinstance(a, int)
True
>>>
isinstance 和 type 的区别在于:
type()不会认为子类是一种父类类型。
isinstance()会认为子类是一种父类类型。
>>> class A:
... pass
...
>>> class B(A):
... pass
...
>>> isinstance(A(), A)
True
>>> type(A()) == A
True
>>> isinstance(B(), A)
True
>>> type(B()) == A
False
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.