Skip to content

petka5/PriorityQMergeSort

Repository files navigation

PriorityQMergeSort

Merging several sorted collections, with different sizes, into one sorted collection via PriorityQueue.

Input collections are wrapped by implementation of PriorityQMergeSort and added to PriorityQMergeSorter

Requirements

Java 1.7 or higher

Getting started

  1. Creates your own implemetation of PriorityQMergeSort to wrap your source collections.
  2. Creates PriorityQMergeSorter and put your wrapped collections into it.
  3. Obtains elements one by one from the PriorityQMergeSorter
  • Example code sorting sorted List of Long elements.
private static Random random = new Random();

public static void main(String[] args) {
        PriorityQMergeSorter<ListElement<List<Long>, Long>, List<Long>, Long> prioritySort = new PriorityQMergeSorter<>();
        prioritySort.add(createElement());
        prioritySort.add(createElement());
        prioritySort.add(createElement());
        while (prioritySort.hasElement()) {
                System.out.println(prioritySort.get());
        }
}
private static ListElement<List<Long>, Long> createElement() {
        List<Long> list = new ArrayList<>();
        fillList(list,random.nextInt(100));
        return new ListElement<List<Long>, Long>(list);
}

private static void fillList(List<Long> list, int size) {
        for (int i = 0; i < size; i++) {
                 list.add(Long.valueOf(random.nextInt(100)));
        }
        Collections.sort(list);
}

You can find implementation of ListElement here.

About

PriorityQMergeSort

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages