English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a function

vector merge_sorted(vector a, vector b)

that merges two sorted vectors,producting a new sorted vector.Keep an index into each vector,
indicating how much of it has been processed already. Each time, append the smallest unprocessed element
from either vector,then advance the index . For eg,

if a is , 1 4 9 16
and b is: 4 7 9 9 11

then merge_sorted returns the vector:

1 4 4 7 9 9 9 11 16

2007-01-05 19:06:59 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

check out http://www.pscode.com for great examples.

2007-01-05 19:16:10 · answer #1 · answered by Richard H 7 · 0 0

Wouldn't your teacher like it better if you wrote it?

Here's an approach though...

1) write a function to sort an array. This could be a simple exchange sort or a complicated quicksort. Can you use an existing sort function?

2) Determine the size of two arrays and allocate a new array equal to the sum size of both.

3) Once the new memory area is created, copy the memory for array1 into the new array. Then copy the memory for array2 into the new array offset by the size of array1.

4) You now have all the data into a single array. Use the sort function to sort the data.

I could write the code for you, but what fun would that be. :)

2007-01-06 03:13:20 · answer #2 · answered by BigRez 6 · 0 0

me taking a dump

2007-01-06 03:08:27 · answer #3 · answered by Anonymous · 0 0

conjunction junction.... what's your function?

2007-01-06 03:07:42 · answer #4 · answered by SST 6 · 0 0

what is this for?

2007-01-06 05:03:20 · answer #5 · answered by Po-ey 1 · 0 0

Huh???!!!!?!?!?!?!

2007-01-06 03:09:48 · answer #6 · answered by Anonymous · 0 0

fedest.com, questions and answers