Skip to content

Commit 1c2a4c5

Browse files
author
exuuguu
committed
add heap example
1 parent 77ca4d2 commit 1c2a4c5

File tree

9 files changed

+441
-39
lines changed

9 files changed

+441
-39
lines changed

data-structure/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

5-
<groupId>com.blaxswan.fundamental</groupId>
5+
<groupId>com.blaxswan.algorithm</groupId>
66
<artifactId>data-structure</artifactId>
77
<version>1.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
@@ -14,6 +14,19 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
</properties>
1616

17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<configuration>
23+
<source>1.6</source>
24+
<target>1.6</target>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
1730
<dependencies>
1831
<dependency>
1932
<groupId>junit</groupId>

data-structure/src/main/java/com/blaxswan/App.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.blaxswan.algorithm;
2+
3+
import com.blaxswan.algorithm.heap.BinaryHeap;
4+
import com.blaxswan.algorithm.heap.BinaryHeapArray;
5+
6+
import java.util.Random;
7+
8+
/**
9+
* Hello world!
10+
*
11+
*/
12+
public class App
13+
{
14+
public static void main(String[] args) {
15+
HeapFoo();
16+
}
17+
18+
private static void HeapFoo(){
19+
final BinaryHeapArray<Integer> heapArray = new BinaryHeapArray<Integer>(BinaryHeap.OrderingType.MAX);
20+
21+
final Random random = new Random();
22+
int i;
23+
String sep = "";
24+
for(i = 0; i < 1500; i++){
25+
int randomInt = random.nextInt(1000);
26+
System.out.print(sep + randomInt);
27+
sep = ", ";
28+
29+
heapArray.add(randomInt);
30+
}
31+
32+
System.out.println();
33+
System.out.println();
34+
System.out.println(heapArray.toString());
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.blaxswan.algorithm.heap;
2+
3+
public interface BinaryHeap<T extends Comparable<T>> extends IHeap<T> {
4+
5+
enum HeapType{
6+
Tree,
7+
Array
8+
}
9+
10+
enum OrderingType{
11+
MIN,
12+
MAX
13+
}
14+
15+
T[] getHeap();
16+
}

0 commit comments

Comments
 (0)