Data Structure - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Data Structure

Description:

Data Structure Week 6 : Tree (Heap / Sort) Homepage : www.cs.hongik.ac.kr/~rhanha E-mail : jhbang_at_cs.hongik.ac.kr Heap Sort Heap ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 11
Provided by: hall1172
Category:
Tags: data | sort | structure | swap

less

Transcript and Presenter's Notes

Title: Data Structure


1
Data Structure
  • Week 6 Tree (Heap / Sort)
  • Homepage www.cs.hongik.ac.kr/rhanha
  • E-mail jhbang_at_cs.hongik.ac.kr

2
??
  • Heap? ??? Sort ?? ??
  • Heap sort ??
  • ?? ??
  • ?? ??
  • HW3 ?????? ??

3
1. Heap sort
? ??(Heap sort) ??? ????? ?? ??? ???? ????
??. ? ??? ????? ?? ??? ???? ?? ?? ??? ??? ?? ? ??
??? ??? ??? ??? ? ?? ? ?? ??? ?? ??. ? ?? ???
????? ?? ?? ?? ???? ??? ??? ??? ????? ?? ?? ?????
?? ???? ????
4
1. Heap sort (cont.)
? ?? 1. ?? ?? ?? 2. ??? ??? ?? ?? ???? ??? ??
?? - n?? ? ???? ?? ? ?? ?? ?????? ? ??? ???
??(n)? ???? ??? ??(?? ?)? ????? ?? -
n-1?? ?? ?????, ?? ???? ? ??? ????? ??.
???? ?? ???? ?? ???? ??? ?? ?? - n-1?? ??
??? ??? ??? ??(n-1)? ???? ?? ??? ????? ??
??? ???? n, n-1, n-2, ? ?? ???? ???? ?????
? ? ?? ??? ?? ????? ??? ??
5
2. Heap sort????
6
2. Heap sort????(cont.)
include ltstdio.hgt void swap(int a, int b) /
?? ?? / int w wa ab
bw
7
2. Heap sort????(cont.)
void main(void) static int heap1000
int n, i, s, p, m n1
while(scanf("d", heapn)!EOF) / ?? ? ?? /
sn ps/2 while(sgt2
heappgtheaps) swap(heapp,
heaps) sn ps/2 n
8
2. Heap sort????(cont.)
0 1 2 3 4 5 6 7 8 9
sn ps/2 n2 p1 n3 p1 n4
p2 n5 p2 n6 p3 n7
p3 n8 p4 n9 p4
9
2. Heap sort????(cont.)
n-- / ??? ?/ mn / n? ??
/ while(ngt1) swap(heap1, heapn)
n-- / ?? ??? ?? ?? / p1 s2p
while(sltn) if(sltn heaps1ltheaps)
s if(heappltheaps)
break swap(heapp, heaps)
ps s2p for(i1iltmi) printf(d,
heapi)
10
3. HW2
  • Heap sort? ??
  • ?????? ???? ???
  • ?? ?
  • Input 8 2 6 4 5 Z
  • Output 2 4 5 6 8
  • ?? ??
  • ??? Heap? ???? ??
  • Due day 5? 2? 24???
Write a Comment
User Comments (0)
About PowerShow.com