Hello everyone,
I have written the followin program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
#define M 40
#define R 5
srand(time(NULL));
srand(6887700);
int *HS=new int [R+1];
int *DT=new int [M+1];
int i, j, k, c, rep, r, m, Temp;
bool flag;
for(m=1;m<=M;++m) DT[m]=(rand()%1000)+1;
for (m=1;m<=M;++m)
{
k=m;
for (j=m+1;j<=M;++j)
{
if (DT[j]<DT[k]) k=j;
}
Temp=DT[m];
DT[m]=DT[k];
DT[k]=Temp;
}
for(m=1;m<=M;++m) printf("%d\n",DT[m]);
for(rep=1;;++rep)
{
flag=false;
for(r=1;r<=R;++r) HS[r]=(rand()%1000)+1;
for(r=1;r<=R;++r)
{
k=r;
for (j=r+1;j<=R;++j)
{
if (HS[j]<HS[k]) k=j;
}
Temp=HS[r];
HS[r]=HS[k];
HS[k]=Temp;
}
for(j=i=1;i<M && j<=R;++i)
{
if(DT[i]==HS[j])
{
flag=true;
break;
}
if(DT[i]<HS[j] && DT[i+1]>HS[j])
{
++j;
if(DT[i]<HS[j] && DT[i+1]>HS[j])
{
flag=true;
break;
}
}
}
if(flag) continue;
for(c=0,j=i=1;j<=R;++i,++c)
{
if(DT[i]>HS[j])
{
if(c<2)
{
flag=true;
break;
}
++j;
c=0;
}
}
if(flag) continue;
for(c=0;i<=M;++i,++c);
if(c<2) flag=true;
if(!flag) break;
}
printf("HS Simulator: %d Replication\n",rep);
for(r=1;r<=R;++r) printf("HS[%3d]:[%9d]\n",r,HS[r]);
printf("\n");
delete [] HS;
delete [] DT;
return 0;
}
and when I test it with "valgrind" it gives the errors:
==28678== Memcheck, a memory error detector.
==28678== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et
al.
==28678== Using LibVEX rev 1471, a library for dynamic binary
translation.
==28678== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==28678== Using valgrind-3.1.0, a dynamic binary instrumentation
framework.
==28678== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et
al.
==28678== For more details, rerun with: -v
==28678==
==28678== My PID = 28678, parent PID = 28088. Prog and args are:
==28678== f
==28678==
==28678== Invalid read of size 4
==28678== at 0x400A59: main (foo.cpp:64)
==28678== Address 0x4A30048 is 0 bytes after a block of size 24
alloc'd
==28678== at 0x4905A0A: operator new[](unsigned long)
(vg_replace_malloc.c:201)
==28678== by 0x400765: main (foo.cpp:14)
==28678==
==28678== ERROR SUMMARY: 5 errors from 1 contexts (suppressed: 4 from
1)
==28678== malloc/free: in use at exit: 0 bytes in 0 blocks.
==28678== malloc/free: 2 allocs, 2 frees, 188 bytes allocated.
==28678== For counts of detected errors, rerun with: -v
==28678== No malloc'd blocks -- no leaks are possible.
Can anybody tell me what is the problem in here?
Thanks,
Mohsen 4 1586
On 22 Sep 2006 18:13:17 -0700 in comp.lang.c++, "Mohsen"
<ja*******@gmail.comwrote,
for(m=1;m<=M;++m) DT[m]=(rand()%1000)+1;
Subscripts run from 0 to size-1
for(m=0;m<M;++m) DT[m]=(rand()%1000)+1;
and...
int *HS=new int [R];
int *DT=new int [M];
and more reindexing.
Nice code, it looks like something out of numerical recipes, what does
it do?
It is a small part of a big program for simulation on genetic
information data.
Thanks,
Mohsen vf***@talktalk.net wrote:
and...
int *HS=new int [R];
int *DT=new int [M];
and more reindexing.
Nice code, it looks like something out of numerical recipes, what does
it do?
I did it. Still there is a problem in line 64.
Thanks,
David Harmon wrote:
On 22 Sep 2006 18:13:17 -0700 in comp.lang.c++, "Mohsen"
<ja*******@gmail.comwrote,
for(m=1;m<=M;++m) DT[m]=(rand()%1000)+1;
Subscripts run from 0 to size-1
for(m=0;m<M;++m) DT[m]=(rand()%1000)+1;
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: B Golash |
last post by:
Hi
I`m trying to install a third-party control. During
the install I receive this error...see the url below.
I have no idea as to the meaning of the error.
...
|
by: Gizmo |
last post by:
hello all have been trying to write a Mid() function a bit like the one in
vb. i come to compile it and there are no errors however when i run it an
error accours and it says the program has to...
|
by: Attila.Rajmund.Nohl |
last post by:
Hello!
I'm using KAI C++ Compiler (KCC) Version 4.0d on Sparc Solaris 8 with
Sun WorkShop 6 update 2 backend (KCC compiles C++ code to C than
uses the Sun compiler to produce machine...
|
by: Morten Gulbrandsen |
last post by:
mysql> USE company;
Database changed
mysql>
mysql> DROP TABLE IF EXISTS EMPLOYEE;
--------------
DROP TABLE IF EXISTS EMPLOYEE
--------------
Query OK, 0 rows affected (0.00 sec)
|
by: Alberto Giménez |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi there! I'm doing some homework (almost finished), but now i'm
reconsidering a design decission I made at the beginning. This is about
error...
|
by: s.subbarayan |
last post by:
Dear all,
I am currently working on a project where we are asked to display
the error logs on the hyperterminal on the press of the key.Typically
the log should collect all the error messages and...
|
by: sudheer786 |
last post by:
A purify error while doing build is setup
--------------------------------------------------------------------------------
Hi all,
I was facing a strange error while trying to run my labeled...
|
by: Jeff |
last post by:
Okay, I'm still new to vb.net 2005 - throught this was a hardware problem,
but now I don't know.
(I'm having some problem with my newgroup provider, so hopefully this will
go through)
This...
|
by: tgnelson85 |
last post by:
Hello, C question here (running on Linux, though there should be no platform specific code).
After reading through a few examples, and following one in a book, for linked lists i thought i would...
|
by: ravishi |
last post by:
Well, this is my first topic at this forum and I'm a newbie on C programming too.
I'm coding a little program and I've used some "dynamic arrays" on it. Compiling and running the program on Linux...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |