-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKeySortDemo.java
63 lines (40 loc) · 1.34 KB
/
KeySortDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package keySorting;
import java.util.Scanner;
public class KeySortDemo {
public static void main(String[] args) {
MusicAlbumClass ma = new MusicAlbumClass();
Scanner sc = new Scanner(System.in);
int n = 0;
int albumIDToSearch = 0;
int posInFile = 0;
System.out.println("Enter the number of time you want to run the program");
n = sc.nextInt();
KeyNodeIndex[] kni = new KeyNodeIndex[n];
for(int i=0; i < n ; i++) {
kni[i]=new KeyNodeIndex(0,0);
}
for(int i=0; i<n; i++) {
ma.getAlbumDetails();
long pos = ma.albumPack();
kni[i].albumIDKey = ma.getAlbumID();
kni[i].recPos = pos;
}
ma.albumUnpack();
KeyNodeIndex.sort(kni);
System.out.println("the key node index contains:");
KeyNodeIndex.displayKeyNodeIndex(kni);
System.out.println("will sort the record file");
KeyNodeIndex.rewriteRecordFile(kni);
System.out.println("done sorting the record file");
System.out.println("enter the album ID to search in new record file");
albumIDToSearch = sc.nextInt();
posInFile = KeyNodeIndex.binarySearchFile(albumIDToSearch);
if(posInFile >=0) {
System.out.println("The album id is present in the file");
MusicAlbumClass.albumUnpackSingleRecord(posInFile);
}
else
System.out.println("The album id is not present in the file");
sc.close();
}
}