* Update: The solution was a deep copy, thanks for the help
I used a vector I am going to simulate some sorting algorithm integer, when I insert the numbers to the vector vector and rotate the order and pass it to a sorting function, if I give the zero vectoring vector the same vector, If the vector is sorted in the function then this The first new sorted vector is passed on to the function after it because it has already been sorted. I can not show the sorting process, for example in my lower code
@SuppressWarnings ( "Uncheck") // int_vec Public ATV vs. CreateVec (int array_len) {vector & lt; Integer & gt; Int_vec = new vector (array_len); Int temp_int = 1; Int low_bound = 0; Int high_bound = array_len - 1; {Int_vec.addElement (temp_int) for (Int i = 0; i & lt; array_len; i ++); // Create a vec in relation to array LAN temp_int ++; } collection. Shuffle (int_vec); System.out.println ("oz vec:" + int_vec); // Original vector (random order) BubbleBurart (int_vec, array_len); // send int_vec to Bubble Sort InsertionSort (int_vec, array_len); / / , my question is as follows, I have given my test vector (int_vec) randomly ordered elements How can I continue to send along, sorted vectors for other algorithms, note that I have implemented these algorithms correctly, if I comment on the function call of other algorithm function, then this Works.
int_vec with new vector & lt; Integer & gt; Copy (int_vec) and pass in the copy for your sorting methods. In this way, only the copy will be resolved, and int_vec will still be ordered randomly, and will be ready to copy again for the next sorting method. And yes, this is a shallow copy, but does not require a deep copy.
No comments:
Post a Comment