Created
May 6, 2013 22:04
-
-
Save supermomonga/5528606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class heapsort { | |
int parent(int i) { | |
// 親を添字を返す | |
return (i - 1) / 2; | |
} | |
int left(int i) { | |
// 左の子の添字を返す | |
} | |
int right(int i) { | |
// 右の子の添字を返す | |
} | |
void MaxHeapify(int[] a, int i, int heapsize) { | |
// MaxHeapifyを実装(heap-sizeは引数で指定) | |
} | |
void BuildMaxHeap(int[] a) { | |
// BuildMaxHeapを実装 | |
} | |
void Heapsort(int[] a) { | |
// Heapsortを実装(ソートすべき配列a[]を入力とし, a[]をソートする.) | |
} | |
public static void main(String[] args) { | |
int i, n; | |
Scanner input = new Scanner(System.in); | |
System.out.print("ソートする配列の要素数: "); | |
n = input.nextInt(); | |
int[] a = new int [n]; | |
for (i = 0; i < n; i++) { | |
System.out.print("a[" + i + "]を入力: "); | |
a[i] = input.nextInt(); | |
} | |
System.out.print("ソート前の配列: "); | |
for (i = 0; i < n; i++) { | |
System.out.print(a[i] + " "); | |
} | |
System.out.println(); | |
heapsort hs = new heapsort(); | |
hs.Heapsort(a); | |
System.out.print("ソート後の配列: "); | |
for (i = 0; i < n; i++) { | |
System.out.print(a[i] + " "); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment