Skip to content
Permalink
Browse files

Correct python typo for data structure

  • Loading branch information...
mbinary committed Apr 4, 2019
2 parents b3f8af6 + 6d8c780 commit 218b3fdbe761be8ea91d80c5dff68c241fd6acec
Showing with 2,491 additions and 1,805 deletions.
  1. +20 −28 .travis.yml
  2. +16 −10 utils/checkBigFile.py
  3. +20 −12 utils/codecogs.py
  4. +9 −6 utils/genReadme.py
  5. +30 −15 utils/genZipFile.py
  6. +10 −7 utils/getSize.py
  7. +23 −14 utils/md_tree_links.py
  8. +5 −4 utils/mywalk.py
  9. +9 −6 utils/pinyinSort.py
  10. +105 −64 数据结构/codes/mbinary/allOone/allOone.py
  11. +48 −33 数据结构/codes/mbinary/allOone/test.py
  12. +139 −110 数据结构/codes/mbinary/bTree.py
  13. +104 −63 数据结构/codes/mbinary/binaryHeap.py
  14. +60 −43 数据结构/codes/mbinary/binaryTree.py
  15. +1 −1 数据结构/codes/mbinary/graph/adjacentList.py
  16. +142 −102 数据结构/codes/mbinary/graph/directed.py
  17. +111 −74 数据结构/codes/mbinary/graph/undirected.py
  18. +44 −30 数据结构/codes/mbinary/hashTable.py
  19. +90 −75 数据结构/codes/mbinary/leftHeap.py
  20. +75 −60 数据结构/codes/mbinary/loserTree.py
  21. +90 −60 数据结构/codes/mbinary/polynomial.py
  22. +129 −99 数据结构/codes/mbinary/redBlackTree.py
  23. +94 −72 数据结构/codes/mbinary/splayTree.py
  24. +74 −40 数据结构/codes/mbinary/trie.py
  25. +70 −59 数据结构/codes/mbinary/winnerTree.py
  26. +114 −75 数据结构/labs/2017/navigation/directed.py
  27. +135 −98 数据结构/labs/2017/navigation/graph.py
  28. +91 −61 数据结构/labs/2017/polynomial/polynomial.py
  29. +256 −211 数理逻辑/codes/mbinary/system_L.py
  30. +97 −75 算法基础/labs/2018-徐云/lab1/PB16030899-朱河勤-实验一.py
  31. +64 −39 算法基础/labs/2018-徐云/lab2/intervalTree.py
  32. +125 −94 算法基础/labs/2018-徐云/lab2/redBlackTree.py
  33. +26 −23 算法基础/labs/2018-徐云/lab3/lcs.py
  34. +65 −42 算法基础/labs/2018-徐云/lab5/directedGraph.py
@@ -1,24 +1,22 @@
language: python3
sudo: required
python:
- "3.6"
language: python
python: "3.6"

notifications:
email:
recipients:
- zhuheqin1@gmail.com
on_success: change # default: change
on_failure: always # default: always
branches:
only:
- master

env:
# Github Pages
- GH_REF: github.com/USTC-Resource/USTC-Course

install:
- sudo apt-get install python3 -y
- sudo apt-get install python3-pip -y
- sudo pip3 install markdown
- sudo pip3 install pypinyin
- pip install --upgrade pip
- pip install flake8 markdown pypinyin

script:
- python3 utils/genReadme.py
- python3 utils/genIndex.py
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
- python utils/genReadme.py
- python utils/genIndex.py

after_script:
# Build Master Repository(Coding Pages)
@@ -31,15 +29,9 @@ after_script:
- git commit -m "Travis-CI Update pages with build $TRAVIS_BUILD_NUMBER"
- git push -f "https://${GH_TOKEN}@${GH_REF}" master:gh-pages

addons:
apt:
update: true

branches:
only:
- master
env:
global:
# Github Pages
- GH_REF: github.com/USTC-Resource/USTC-Course

notifications:
email:
recipients:
- zhuheqin1@gmail.com
on_success: change # default: change
on_failure: always # default: always
@@ -4,29 +4,35 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-p','--path',help='path to check',default='.')
parser.add_argument('-s','--size',help='max size of file to be removed',default=2**20*100) # 100Mb
parser.add_argument('-p', '--path', help='path to check', default='.')
parser.add_argument(
'-s', '--size', help='max size of file to be removed',
default=2**20 * 100) # 100Mb
args = parser.parse_args()

PATH = args.path
SIZE = args.size
def checkBigFile(path,size):


def checkBigFile(path, size):
big = '.bigFile'
if not os.path.exists(big):
os.mkdir(big)
gen = os.walk(os.path.abspath(path))
for path,dirs,files in gen:
for path, dirs, files in gen:
li = path.strip(os.sep).split(os.sep)
if any([i[0]=='.' and i!='.' for i in li]):continue
if any([i[0] == '.' and i != '.' for i in li]): continue
for file in files:
filePath = os.path.join(path,file)
filePath = os.path.join(path, file)
sz = os.path.getsize(filePath)
if sz > size:
print('[BIG]: {} is bigger than 100mb'.format(filePath))
try:
shutil.move(filePath,big)
shutil.move(filePath, big)
except Exception as e:
print(e,path)
print(e, path)
os.remove(filePath)
if __name__=='__main__':
checkBigFile(PATH,SIZE)


if __name__ == '__main__':
checkBigFile(PATH, SIZE)
@@ -3,39 +3,47 @@
import sys
from translate import Translator as TR

FORMULA = re.compile(r'\${1,2}(?P<formula>.+?)\${1,2}',re.DOTALL)
FORMULA = re.compile(r'\${1,2}(?P<formula>.+?)\${1,2}', re.DOTALL)
Chinese = re.compile(u"(?P<chinese>[\u4e00-\u9fa5]+)")
API = 'https://latex.codecogs.com/gif.latex?'


def codecog(f):
if os.path.exists(f) and f.endswith('.md'):
with open(f) as fp:
txt = fp.read()
with open(f,'w') as fp:
fp.write(re.sub(FORMULA,covert,txt))
with open(f, 'w') as fp:
fp.write(re.sub(FORMULA, covert, txt))
else:
s = re.sub(FORMULA,covert,f)
s = re.sub(FORMULA, covert, f)
print(s)


def covert(matched):
s = matched.group('formula').strip('$ ')
s = re.sub(Chinese,zh2en,s)
s = re.sub(r'\r+|\n+|\\n',' ',s)
s = re.sub(' +','&space;',s)
return '![]({})'.format(API+s)
s = re.sub(Chinese, zh2en, s)
s = re.sub(r'\r+|\n+|\\n', ' ', s)
s = re.sub(' +', '&space;', s)
return '![]({})'.format(API + s)


def zh2en(txt):
s = txt.group('chinese').strip()
tran = TR(to_lang='en',from_lang='zh')
tran = TR(to_lang='en', from_lang='zh')
en = tran.translate(s)
return re.sub(' +','-',en)
return re.sub(' +', '-', en)


def handle(path):
if os.path.isdir(path):
for p,ds,fs in os.walk(path):
for p, ds, fs in os.walk(path):
for f in fs:
if f.endswith('.md'):
codecog(os.path.join(p,f))
codecog(os.path.join(p, f))
else:
codecog(path)


if __name__ == '__main__':
args = sys.argv[1:]
if not args:
@@ -5,17 +5,20 @@

parser = ArgumentParser()

parser.add_argument('-p','--path',default='.',help='path to walk')
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
parser.add_argument('-d','--depth', type = int, default = 1)
parser.add_argument('-p', '--path', default='.', help='path to walk')
parser.add_argument(
'-f',
'--fileinclude',
action='store_true',
help='if has, list files and dirs, else only dirs')
parser.add_argument('-d', '--depth', type=int, default=1)
#获取参数
args = parser.parse_args()
FILE = args.fileinclude
PATH = args.path
DEPTH = args.depth


idxs = tree(PATH,DEPTH,FILE)
idxs = tree(PATH, DEPTH, FILE)
s = README.format(index='\n'.join(idxs))
with open('README.md','w') as f:
with open('README.md', 'w') as f:
f.write(s)
@@ -7,47 +7,62 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-r','--rewrite',help='rewrite zip file',action='store_true')
parser.add_argument(
'-r', '--rewrite', help='rewrite zip file', action='store_true')
args = parser.parse_args()
REWRITE = args.rewrite


def checkZip(name):
'''check if this file should be added to the zip'''
li = [name.startswith('.') ,name.endswith('.zip'),name.lower()=='readme.md']
li = [
name.startswith('.'),
name.endswith('.zip'),
name.lower() == 'readme.md'
]
return not any(li)

def isIgnore(li,files):
return 'index.html' in files or any((i[0]=='.' and i!='.') or i.startswith('__') or i in IGNORE for i in li)
def genZipFile(tar = WALKDIR,rewrite=False):

def isIgnore(li, files):
return 'index.html' in files or any(
(i[0] == '.' and i != '.') or i.startswith('__') or i in IGNORE
for i in li)


def genZipFile(tar=WALKDIR, rewrite=False):
os.chdir(tar)
n = len(tar)
gen = os.walk(tar)
pwd = os.path.abspath('.')
for path, dirs, files in gen:
li = path.strip(os.sep).split(os.sep)
if isIgnore(li,files):continue
if isIgnore(li, files): continue
ziplst = []
for i in files:
if i.endswith('个文件.zip'):
if rewrite:
os.remove(os.path.join(path,i))
else:break
os.remove(os.path.join(path, i))
else:
break
elif checkZip(i):
ziplst .append(i)
ziplst.append(i)
else:
if len(ziplst)<3:continue
if len(ziplst) < 3: continue
ziplst.sort()
tmp = os.path.abspath(path) \
.replace(pwd,'')\
.replace(os.sep,'-')
name = '{tmp}目录下的{length}个文件.zip'.format(tmp=tmp,length =len(ziplst))
zipName = os.path.join(path,name)
name = '{tmp}目录下的{length}个文件.zip'.format(
tmp=tmp, length=len(ziplst))
zipName = os.path.join(path, name)
try:
with ZipFile(zipName,'w') as z:
with ZipFile(zipName, 'w') as z:
os.chdir(path)
for i in ziplst: z.write(i)
for i in ziplst:
z.write(i)
except Exception as e:
print(e,path)
print(e, path)


if __name__ == '__main__':
genZipFile(rewrite=REWRITE)
@@ -1,30 +1,33 @@
# coding: utf-8
import os
import sys


def formatSize(size):
s = 'BKMGTP'
ct = 0
while size>=(1<<ct):
ct+=10
if ct>=10: ct-=10
return '{sz:.2f}{a}'.format(sz=size/(1<<ct),a=s[ct//10])
while size >= (1 << ct):
ct += 10
if ct >= 10: ct -= 10
return '{sz:.2f}{a}'.format(sz=size / (1 << ct), a=s[ct // 10])


def getSize(path='.'):
if os.path.isdir(path):
gen = os.walk(path)
li = []
li = []
for root, dirs, files in gen:
for f in files:
sz = os.path.getsize(os.path.join(root ,f))
sz = os.path.getsize(os.path.join(root, f))
li.append(sz)
#li.insert(('.',sum(i[1] for i in li)),0)
#size = [f'{i[0]}: {formatSize(i[1])}' for i in li]
return formatSize(sum(li))
else:
return formatSize(os.path.getsize(path))


if __name__ == "__main__":
items = sys.argv[1:]
for i in items:
print('{i}: {sz}'.format(i=i,sz =getSize(i)))
print('{i}: {sz}'.format(i=i, sz=getSize(i)))
@@ -6,40 +6,49 @@
#命令行输入参数处理
parser = ArgumentParser()

parser.add_argument('-p','--path',default='.',help='path to walk')
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
parser.add_argument('-d','--depth', type = int, default = 2)
parser.add_argument('-p', '--path', default='.', help='path to walk')
parser.add_argument(
'-f',
'--fileinclude',
action='store_true',
help='if has, list files and dirs, else only dirs')
parser.add_argument('-d', '--depth', type=int, default=2)
#获取参数
args = parser.parse_args()
FILE = args.fileinclude
PATH = args.path
DEPTH = args.depth


def mklink(path):
return '* [{name}]({path})'.format(name=os.path.basename(path),path=path)
return '* [{name}]({path})'.format(name=os.path.basename(path), path=path)


def clean(paths):
ret = []
for path in paths:
name = os.path.basename(path)
if not ( name.startswith('.') or name.startswith('__')):
if not (name.startswith('.') or name.startswith('__')):
ret.append(path)
return ret

def tree(path='.',depth=2,showfile=False):

def tree(path='.', depth=2, showfile=False):
while not os.path.isdir(path):
print('[error]: please input a directory, not file path')
path = input()
li = os.listdir(path)
items = [os.path.join(path,i) for i in li if not i.startswith('.')]
items = [os.path.join(path, i) for i in li if not i.startswith('.')]
items = clean(items)
items = pinyinSort(items)
if not showfile: items = [i for i in items if os.path.isdir(i)]
if depth==1:
return [mklink(path)] + [' '*4 + mklink(i) for i in items]
if depth == 1:
return [mklink(path)] + [' ' * 4 + mklink(i) for i in items]
else:
uls = [tree(i,depth-1,showfile) for i in items]
ret = [' '*4 + li for ul in uls for li in ul]
return [mklink(path)] + ret
uls = [tree(i, depth - 1, showfile) for i in items]
ret = [' ' * 4 + li for ul in uls for li in ul]
return [mklink(path)] + ret


if __name__ =='__main__':
print('\n'.join(tree(PATH,DEPTH,FILE)))
if __name__ == '__main__':
print('\n'.join(tree(PATH, DEPTH, FILE)))
@@ -1,17 +1,18 @@
import os

def mywalk(dire,valid=lambda x:True):

def mywalk(dire, valid=lambda x: True):
if not os.path.isdir(dire):
raise Exception('[Error]: directory excepted')
dirs = []
files = []
for i in os.listdir(dire):
i = os.path.join(dire,i)
i = os.path.join(dire, i)
if valid(i):
if os.path.isdir(i):
dirs.append(i)
else:
files.append(i)
yield dire,dirs,files
yield dire, dirs, files
for d in dirs:
yield from mywalk(os.path.join(dire,d),valid)
yield from mywalk(os.path.join(dire, d), valid)

0 comments on commit 218b3fd

Please sign in to comment.
You can’t perform that action at this time.