inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Python 응용 - 파이썬으로 배우는 자료구조와 알고리즘

heap 생성, 힙 아이템 삭제 및 수정, 힙의 최대, 최소 값 구하기

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

729

oncore

작성한 질문수 1

0

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

python

답변 15

0

MyungHak

'''

피이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

파이썬 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

"""

Breadth (등락 비율) 분석

0

9

1

교육자료가 너무 오래되어서 지시한대로 진행하려 해도 안됩니다.

0

7

1

작업형1 - 연습문제 16~39 풀이는 몇강을 보면 되나요?

0

14

1

26 .강의 프롬프트와 프롬프트파일(part3) 내용이 차이가 있어요.

0

20

2

작업형 1 -연습문제 4-6

0

21

1

구글 그래피티 마켓 오류...?!

0

28

2

디스코드 소통창구는 없어졌나요 ??

0

27

2

FOREIGN KEY 정리하기, 영상대로 SQL코드 복붙해도 안되요.

0

19

1

모델 서빙과 관련된 강좌 출시 예정된 바가 있으신지 여쭤봅니다!

0

24

2

모델 서빙과 관련된 강좌가 출시되는지 질문드립니다.

0

19

2

20번강좌에 대한 질문입니다.

0

25

2

6-6

0

28

1

작업형 1 유형 부분

0

30

2

수강평 이벤트

0

26

2

작업형 1 (삭제예정, 구 버전)

0

44

2

강의노트는 어디있나요?

0

21

1

노션 학습 자료 권한 요청

0

27

2

수강기간 연장 문의드립니다.

0

29

1

2유형 레이블 인코딩 VS 원핫 인코딩

0

32

3

part2강의 문의사항입니다.

0

35

2

수강기간 연장 문의드립니다.

0

32

1

인덱스 슬라이싱

0

33

2

bisect와 힙의 속도차이

0

361

0

감사합니다.

0

281

0