How im seeing my issue, please tell me where im going wrong? Cheers
Book[] booksArray = new Book[10];
Book[] sortedBooks = new Book[10];
2 Different arrays of Book Objects, correct? (assume they have data, cbf posting all code)
sortedBooks = booksArray;
sortedBooks is now a duplicate of booksArray, yes?
sortBooksByPrice(sortedBooks, numOfBooks);
public static void sortBooksByPrice(Book[] sortedBooks, int numOfBooks)
{
Book objHolder;//For the purpose of swapping/sorting
for(int i = 0; i < numOfBooks; i++)
{
if(numOfBooks > (i +1))
{
if(Double.parseDouble(sortedBooks[i].getPrice()) >
Double.parseDouble(sortedBooks[i+1].getPrice()))
{
objHolder = sortedBooks[i];
sortedBooks[i] = sortedBooks[i+1];
sortedBooks[i+1] = objHolder;
}
}
}
displayAllBooks(sortedBooks, numOfBooks);
}
displays sortedBooks as expected, but now if I call
displayAllBooks(booksArray , numOfBooks);
It will display sortedBooks instead. Whats going on here? D: