473,412 Members | 4,519 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

two arrays merging into new array minus duplicates

5
I have same question as posted by holla and Iam not sure about merging the contents of 2 sorted arrays into another array without duplication of values.
Mar 9 '13 #1
9 5347
weaknessforcats
9,208 Expert Mod 8TB
OK. So what is your question exactly?
Mar 10 '13 #2
perogy
5
Question is write a function that will merge the contents of two sorted arrays of type double values, sorting the result in an array output of parameter (still in ascending order). This function should not assume that both its input parameters are the same length but can assume that one array does not contain two copies of the same value. The result array should not contain duplicate values.
Mar 10 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
Yes, I understand the question that is your assignment but you haven't said exactly where you are stuck.
Mar 10 '13 #4
perogy
5
merging the contents- is it strngcpy
Mar 11 '13 #5
jmrker
17
Ignore following javascript solution.
I did not realize I was posting to the wrong forum.
Sorry :(


This does not remove duplicates since you are not stuck on that part.
The correct command is concat()

Here are two examples.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var arr1 = [1,2,3,4,5];
  3. var arr2 = ['a','b','c','d','e','f','g','h','i','j'];
  4. var arrs = [].concat(arr1,arr2);
  5. alert(arrs.join('\n'));
  6. alert(arr2.concat(arr1).join('\n'));
  7. </script>
  8.  
Mar 11 '13 #6
weaknessforcats
9,208 Expert Mod 8TB
@jmrker
This is the C/C++ forum. Not Javascript.

@perogy:
No it's not strncpy. I suspect that you don't know the steps required to do a merge.

So If you merge array A,say 10 elements, and array B, say 20 elements, into array C you would need to:

1) sort A
2 sort B
3) allocate C for 30 elements (incase there are n duplicates)
4) copy either A or B to C
5) now the merge:
is A[0] in C? If yes, do nothing. If no, add A[0] to the end of C
6) repeat step 5 for all elements of A
7 sort C
8 done.

You can never code until you know what to code. So writng a small outline of the logic is important. Then you code the outline.

Post again with your code.
Mar 11 '13 #7
perogy
5
Thanks all of you for giving me the idea. The second answer is what was on my mind but I wasnt sure about the merge without the duplicates. Now I know that I can check each element of array c with the element in array a first and then b and then copy them into c.
Mar 11 '13 #8
donbock
2,426 Expert 2GB
You are directed to eliminate duplicate values when you merge the two arrays. That would be straightforward for merging arrays of integers but you are working with arrays of doubles. It is usually bad form to test floating point numbers for equality. Read what every computer scientist should know about floating-point arithmetic for a very detailed explanation.
Mar 11 '13 #9
perogy
5
Thank you for all the suggestions
Mar 12 '13 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Robert | last post by:
Im a beginner in PHP and Im having a problem with this code. Im trying to remove duplicate elements from an array created via $_GET. I want users to be able to click on a link which sends an email...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
2
by: Rob | last post by:
Hi, I want to create an arraylist of multidimension arrays. Currently I've managed to do these via conventional means as follows: Dim myarraylist As ArrayList = New ArrayList() Dim...
1
by: agsupriya86 | last post by:
Hi, I have a LinkedList of arrays ,Each array containing certain keywords..i need to take the union of all keywords presents in all the arrays of the linked list...that is removing the duplicates...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
40
by: kylie991 | last post by:
Hi I am stuck on checking if a 2D array has duplicates. I have to write a function to check if a column has duplicates and then another function to check if the rows have duplicates from a file. ...
7
by: riotking | last post by:
Hi all, I've been stuck on this for hours so am brining it here to see if i can get any suggestions.. I have an array that i need to check to see if there are any duplicate values present. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.