How can I extract common elements of two number arrays into another
array?
// the following doesn't work
for(k=0;k<10;k+ +)
for(l=0;l<15;l+ +)
if(p[k]==q[l]) {r[m]=p[k];++m;} 7 1839
In article <11************ **********@i13g 2000prf.googleg roups.com>,
Umesh <fr************ ****@gmail.comw rote:
>How can I extract common elements of two number arrays into another array?
// the following doesn't work
for(k=0;k<10;k+ +) for(l=0;l<15;l+ +) if(p[k]==q[l]) {r[m]=p[k];++m;}
What doesn't work about it?
You need to show us a complete program.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
"Umesh" writes:
How can I extract common elements of two number arrays into another
array?
// the following doesn't work
for(k=0;k<10;k+ +)
for(l=0;l<15;l+ +)
if(p[k]==q[l]) {r[m]=p[k];++m;}
Congratulations Umesh! You finally figured out that the question belongs in
the message. The code fragment you posted doesn't show any means of starting
m at 0. Does the real code take care of that?
On 15 Jun, 13:55, Umesh <fraternitydisp o...@gmail.comw rote:
How can I extract common elements of two number arrays into another
array?
// the following doesn't work
for(k=0;k<10;k+ +)
for(l=0;l<15;l+ +)
if(p[k]==q[l]) {r[m]=p[k];++m;}
This code looks OK to me, as long as you set m to zero beforehand and
r is big enough. The one snag I can see is that, if an element occurs
more than once in a list, and at least once in the other, it may be
selected in r more times than you want. One way round that might be to
change the value in p to some sort of non-value (eg you could use 0,
or -1, if this wasn't going to occur in the real data). An alternative
might be to have another array to indicate whether the value in p had
been "used" yet or not. It's up to you.
Hope this helps.
Paul. gw****@aol.com writes:
On 15 Jun, 13:55, Umesh <fraternitydisp o...@gmail.comw rote:
>How can I extract common elements of two number arrays into another array?
// the following doesn't work for(k=0;k<10;k+ +) for(l=0;l<15;l+ +) if(p[k]==q[l]) {r[m]=p[k];++m;}
This code looks OK to me, as long as you set m to zero beforehand and
r is big enough. The one snag I can see is that, if an element occurs
more than once in a list, and at least once in the other, it may be
selected in r more times than you want. One way round that might be to
change the value in p to some sort of non-value (eg you could use 0,
or -1, if this wasn't going to occur in the real data). An alternative
might be to have another array to indicate whether the value in p had
been "used" yet or not. It's up to you.
That "other array" already exists (r). If I were forced to use this
rather inefficient method, I'd write a "membership " function:
int in(int x, int p[], int l)
{
/* Return 1 if x is equal to any element in p[0]..p[l-1]; 0 otherwise */
int k;
for (k = 0; k < l; k++)
if (x == p[k])
return 1;
return 0;
}
and then do something like:
for (k = 0; k < sz1; k++)
if (!in(p[k], r, m) && in(p[k], q, s2))
r[m++] = p[k];
A much better way, is to sort p and q and the do a sort of
"anti-merge". That will be much faster for large arrays.
--
Ben.
Count no. of same elements in an number array and then display the
result.
On Jun 16, 7:34 pm, Umesh <fraternitydisp o...@gmail.comw rote:
Count no. of same elements in an number array and then display the
result.
using this code if same number is there in any of the array more than
once,
it will copy again. Is it really needed?
Umesh wrote:
Count no. of same elements in an number array and then display the
result.
I get `17`.
--
Chris "DYOH" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nazgul |
last post by:
Hi!
I want to implement a small tool in Python for distributing "patches" and I
need Your advice. This application should be able to package all files
chosen by a user into a self-extracting.exe so that when you click on it, it
will extract the files and run setup.exe which among the other will copy
these files into respective folders (the absolute paths could be written in
some config file). Of course the files should be extracted first...
|
by: Avi |
last post by:
hi,
Can anyone tell me what the problem is and how to solve it
The following piece of code resides on an asp page on the server and
is used to download files from the server to the machine accessing the
abobe mentioned asp page. It WORKS for every type of file when I
change the content type according to the file type, but it won't work
with self extracting files. When an end user downloads a self
extracting file by accessing the...
|
by: effendi |
last post by:
How can I extract differences between two arrays using Javascript?
I hv for example, apple, orange, pear and another array with apple,
orange and I would like to get pear.
Thanks.
|
by: Digital Puer |
last post by:
Hi, suppose I have an unsigned long long. I would like to extract
the front 'n' bits of this value and convert them into an integer.
For example, if I extract the first 3 bits, I would get an int between
0 and 7 (=2^3-1). Could someone please help out?
I can assume the largest returned value fits in an int. Also,
I'm on a big-endian PPC (AIX), in case that matters.
Ideally, I'd like to implement a prototype like:
int...
|
by: k_nil |
last post by:
I have a link on my web page for a self extracting executable file placed on
the server. When the link is clicked,
1) i could see dialog box with open or save options
2) when open clicked, self extracting exe starts.
But...the self extracting exe when downloaded on my mahcine, creates a wierd
named folder in c:\.
how would this folder getting cretaed? Can i make to create this folder in
temp files.
| |
by: bjm |
last post by:
I created a self extracting zip file with about 9000 files in it. I
extracted it manually from the command line without a problem.
However, when I tried to do the same extraction at the same location
with the same arguments (using the Process class), a command prompt
opens, and it begins extracting files. After about 70 files have been
extracted, the main form for my application loses focus and I get an
hourglass cursor (which is normal,...
|
by: rpjd |
last post by:
I am completely new to this so please bear with me here. My project involves a webpage executing php scripts via an xmlhttprequest which queries a database and returns data to the webpage. This code below is working to a degree in IE7. As I have not yet parsed http.responseText, I am getting all the code in parts.php in the alert. My php script query creates two php arrays, one a single array and a two-dimensional array such as array. My...
|
by: Werner |
last post by:
Hi,
I try to read (and extract) some "self extracting" zipefiles on a
Windows system. The standard module zipefile seems not to be able to
handle this.
False
Is there a wrapper or has some one experience with other libaries to
|
by: Mukesh |
last post by:
Hi,
I am using framework 2.0. I am writing a foreach loop that will
extract single dimensional arrays out of double dimensional array. I
am trying writing something like this.
string strDetails
foreach(string str in strDetails)
{
//Code comes here
}
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |