Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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.