Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
forspy
python
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
python
/
test_py_module3_STL2.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
41 lines (35 loc) · 1.51 KB
master
Breadcrumbs
python
/
test_py_module3_STL2.py
Copy path
Top
File metadata and controls
Code
Blame
41 lines (35 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# python中的数据结构
# 1.集合set
print(set(range(10)))
print(set([1, 1, 1])) # set只接受同一元素最多一个
print({1, 2, 3, 4, 5, 6, 6, 6}) # 花括号也能创建set
# 2.堆heap
# 这里的堆表示一种数据结构 它时一种优先队列 功能:能够以任意顺序添加对象 并找出最小元素 (相对于min方法效率高得多)
# python里面的堆数据结构需要依靠模块导入
from heapq import *
from random import shuffle
data = list(range(10))
shuffle(data) # 随机排序列表
print(data)
heap = [] # 创建一个heap对象
for n in data: # 遍历data,python的另一个特点是遍历机制简单 相较于c/c++的下标位置来说 python直接在for循环里面拿到了该值 但有利有弊
heappush(heap, n) # 将n压入堆
print(heap) # 这里有一个问题就是顺序压入堆以后,堆又进行了调整,但是不管怎么调整,堆的第一个元素必定是最小值
print('3//2=', 3 // 2)
# 堆排序的特征 位置i处的元素总是大于位置i//2处的元素
for i in range(10):
print(heappop(heap)) # heappop能弹出堆中最小的元素
l = [12, 234, 234, 34, 1, 34, 5, 6, 6]
heapify(l) # heapify快速将一个列表转化为堆结构 ,那么转化为堆数据结构有什么好处呢?待解决
print(l)
# 3.双端队列deque
from collections import deque
q = deque(range(0, 4))
q.append(5)
q.appendleft(6)
print(q)
q.rotate(1) # 依次往后移动一位
print(q)
q.rotate(-1) # 依次往前移动一位
print(q)
# 双端队列是循环链表
You can’t perform that action at this time.