
November 15th, 2006, 03:14 PM
|
Contributing User
|
|
Join Date: Nov 2006
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
how to insert an element into a sorted array (Java)
I am having difficulty with a question in an assignment.
in the class, we are managing booklists objects. which are essentially arrays that hold book objects (book class is given to us).
we are supposed to write an insert() class where i need to insert a reference to a book object into the array, and i already have a method which compares the book to the others and gives me a positive, 0, or negative number if the book is after, in the position, or before the book it is being compared to respectively.
(and the list is already sorted alphabetically so i don't need to do sort it).
the problem i have is actually inserting the book in the required position and "pushing" all the other books forward one space in the array.
the other problem is that once the array is full i need to transfer everything to a bigger array - twice it's size..
and of course - we're ment to do this without using arrayList, but normal arrays.
also - this is an introductory course so we're not really ment to use anything we haven't learned so far. we covered the for, while, do-while loops and general conditional statements and arrays. and we're not allowed to use any array methods.
any help with this will be GREATLY apreciated.
i wrote a single line and don't know where to go from there.
i'm completely new in programming
|