I am working on a CS-101 assignment and am only allowed to use a single array. I have an array that looks like the following:
[Song, Song, Album, Fiction, Movie, Nonfiction, Song]
Here is the hierarchy for background (requirements from my assignment):
“At the top level you will have a class called Library. Library will have three subclasses: Music, Book, and Movie. Music will have two subclasses: Song and Album. Book will have two subclasses: Fiction and Nonfiction. Movie, Fiction, Nonfiction, Song,
and Album will not have any subclasses.”
I am currently trying to write a method that will sort the Books by their ISBN number. So Fiction and Nonfiction are subclasses of my Book class, which is a subclass of Library.
I hold everything in Library myLibrary[] = new Library[100];
I’m not sure how to go about retrieving the ISBN’s from the Books only and sort them since I am only allowed one array; otherwise I would love to make an array of Books, then sort those separately.
What are some hints / algorithms that I can utilize to accomplish this?
Update
I can post more code if needed. But this question is currently more focused on the approach.
Without trying to give the actual implementation of the algorithm, you should do an in-place sort where priority can be done by:
1. Books have more priority than Music and Movies
2. If two objects are Books then priority is based on ISBN