showHeap 파일 소스코드좀 부탁해요

18.05.08 22:22 작성 조회수 274

0

강의가 중간에 끊켰는지 ? 갑자기 아무설명도 없다가 showHeap이 나와서 강의 진행하는데 소스 코드좀 부탁드립니다

답변 15

·

답변을 작성해보세요.

0

MyungHak님의 프로필

MyungHak

2018.05.14

'''

피이썬 3.x 버젼과 2.x버젼의 차이가 있으니 유의해주시기 바랍니다.

이 코드는 이전 강의에서 댓글로 써주신 분 것을 가져온거입니다

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

output = StringIO() # for 3.x

#output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

'''

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""

0

MyungHak님의 프로필

MyungHak

2018.05.14

파이썬 2.x버젼과 3.x버젼이 차이가 있으니 주의해 주세요

그리고 이 코드는 이 전 강의에서 댓글로 소스코드를 올려주신 분 것 입니다.

"""

import math

from io import StringIO, BytesIO

3.x 는 String IO,

2.x는 BytesIO 사용바람

def show_tree(tree, total_width=36, fill= ' '):

Pretty-print a tree

#output = StringIO() # for 3.x

output = BytesIO() # for 2.x

last_row = -1

for i, n in enumerate(tree):

if i:

row = int(math.floor(math.log(i+1, 2))) # 지수, 밑

# i =0부터 시작돼서 i+1, 이진트리기떄문에 밑은 2

else:

row =0

if row!= last_row:

output.write('\n')

columns = 2**row

col_width = int(math.floor((total_width * 1.0) / columns ))

output.write(str(n).center(col_width, fill))

last_row = row

print(output.getvalue())

print('-'*total_width)

print()

return

"""