473,786 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove double entries from a sorted array

ebc
Hi,

I have written a function that removes double entries from a sorted
array.

See the structures
typedef struct tagRECR
{
char name[LEN_NAME+1];

}
REC;
// the REC structure is filled dynamic (malloc...)
typedef struct tagTAB
{
int count; // count of itemes in lief
REC *lief; // dynamic generated list
// belegte anz Eintr,,ge
}
TAB;

Now the function

void removedoubleent ries( TAB *tab )
{
int i,j;
RECL *source;
RECL *dest;
BOOL found;

source = tab->lief;
dest = source;

j=0;
found = FALSE;

for (i = 0; i < tab->count-1; i ++ )
{
if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
{
*(dest+j) = *(source+i);
j++;
found = FALSE;
}
else
found = TRUE;
}
// Now I am not sure if this is correct
// for the last entrie
*(dest+j) = *(source+i);
j++;
tab->count = j;

}

ebc

Nov 15 '05 #1
6 2962
ebc wrote:
I have written a function that removes double entries from a sorted
array.

See the structures
typedef struct tagRECR
{
char name[LEN_NAME+1];

}
REC;
// the REC structure is filled dynamic (malloc...)
typedef struct tagTAB
{
int count; // count of itemes in lief
REC *lief; // dynamic generated list
// belegte anz Eintr,,ge
}
TAB;

Now the function

void removedoubleent ries( TAB *tab )
{
int i,j;
RECL *source;
RECL *dest;
BOOL found;

source = tab->lief;
dest = source;

j=0;
found = FALSE;

for (i = 0; i < tab->count-1; i ++ )
{
if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
{
*(dest+j) = *(source+i);
j++;
found = FALSE;
}
else
found = TRUE;
}
// Now I am not sure if this is correct
// for the last entrie
*(dest+j) = *(source+i);
j++;
tab->count = j;

}


Why not use ordinary array notation; `dest[j] = source[i]' etc?

August
Nov 15 '05 #2
ebc wrote:
Hi,

I have written a function that removes double entries from a sorted
array.
Please state what you are looking for
- a code review?
- finding the solution of a problem/if yes, which problem?

See the structures
typedef struct tagRECR
{
char name[LEN_NAME+1];

}
REC;
// the REC structure is filled dynamic (malloc...)
typedef struct tagTAB
{
int count; // count of itemes in lief
I would rather use size_t instead of int -- the guaranteed upper
bound of int is 32K-1...
REC *lief; // dynamic generated list
// belegte anz Eintr,,ge
}
TAB;

Now the function

void removedoubleent ries( TAB *tab )
{
int i,j;
RECL *source;
RECL *dest;
The type RECL is not defined.
BOOL found;
The type BOOL is not defined.

Please do not post as-if-code but copies of the real thing.

source = tab->lief;
dest = source;

j=0;
found = FALSE;
What do you need found for?
for (i = 0; i < tab->count-1; i ++ )
{
if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
If you want to use pointers, use pointers, i.e. update source in
the loop update statement by source++ and
compare source->name and source[1].name/(source+1)->name.

Otherwise, use array index access as it is easier to read:
if ( strcmp(source[i].name, source[i+1].name) != 0 )

If you do not have many double first letters, you can speed up this
check:
if ( source[i].name[0] != source[i+1].name[0]
|| strcmp(source[i].name, source[i+1].name) != 0 ) {
*(dest+j) = *(source+i);
j++;
with pointer arithmetics
*(dest++) = *source;
(parentheses not necessary).
Part array/part pointer:
*dest++ = source[i];
found = FALSE;
}
else
found = TRUE;
}
// Now I am not sure if this is correct
// for the last entrie
*(dest+j) = *(source+i);
Have you tried it?
j++;
tab->count = j;

}


Why don't you give us something that compiles and tell us
your problem?

Note: Uppercase name are traditionally used for macros -- I
would rather not use them for typedefs.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #3
cannot catch wot you mean

Nov 15 '05 #4
In article <11************ *********@g44g2 000cwa.googlegr oups.com>,
<un**********@g mail.com> wrote:
cannot catch wot you mean


ITYM:

cannut ketch wt u mn

Nov 15 '05 #5
On 2 Aug 2005 07:43:47 -0700, "ebc" <ce****@gmx.a t> wrote:
Hi,

I have written a function that removes double entries from a sorted
array.

See the structures
typedef struct tagRECR
{
char name[LEN_NAME+1];

}
REC;
// the REC structure is filled dynamic (malloc...)
typedef struct tagTAB
{
int count; // count of itemes in lief
REC *lief; // dynamic generated list
// belegte anz Eintr,,ge
}
TAB;

Now the function

void removedoubleent ries( TAB *tab )
{
int i,j;
RECL *source;
What is a RECL?
RECL *dest;
BOOL found;

source = tab->lief;
source is a RECL*. tab->lief is a REC*. This is a syntax error
unless one of them is a synonym for void* and we know REC* is not.
Why don't you show us your real code? Use cut and paste; don't
retype.
dest = source;

j=0;
found = FALSE;
This value will survive only if tab->count <= 1.

for (i = 0; i < tab->count-1; i ++ )
{
if ( strcmp ( (source+i)->name, (source+1+i)->name) !=0 )
source[i].name saves a couple of keystrokes and is easier on the eyes.
{
*(dest+j) = *(source+i);
As is dest[j].
j++;
found = FALSE;
What is found used for?
}
else
found = TRUE;
}
// Now I am not sure if this is correct
// for the last entrie
*(dest+j) = *(source+i);
j++;
Only if the above copy is performed. Maybe you should be using found
here. But watch out if tab->count is 0.
tab->count = j;

}

ebc


<<Remove the del for email>>
Nov 15 '05 #6
ebc
Thanks for reply all of you..

I have not just copy the original code because the variables are in
german. So for better reading i give you the code "translated " to
english.

First of all I' am looking if this could be work. I can not test it
yet.

-RECL is a syntax error it should be REC. -> re typing error :-)

<I would rather use size_t instead of int -- the guaranteed upper
bound of int is 32K-1... >
--> int is okay this array has a limit to 100 items. ( makes another
part of my program )

@Barry Schwarz and all others

I give you the original code

typedef struct tagRECLIEFNR
{
char vertrag[LEN_SAP_AUFTRAG +1];
char lieferscheinnr[LEN_SAP_LSCHEIN +1];
char liefText[LEN_SAP_LIEFTXT +1];
int stk;
}
RECLIEFNR;
typedef struct tagTABLIEFNR
{
int anz; // = counts of lief
int size; // Gr"áe Feld lief
RECLIEFNR *lief; // dynamic Filed with size size and count anz
}
TABLIEFNR;
static void RemoveDoppelteL SEintraege( TABLIEFNR *tsource )
{
int i,j;
RECLIEFNR *source;
RECLIEFNR *dest;

source = tsource->lief;
dest = source;

j=0;
i=0;
//found = FALSE;

if ( tsource->anz-1 < 0 )
return;

for (i = 0; i < tsource->anz-1; i ++ )
{
// no double entrie
if ( strcmp ( (source+i)->lieferscheinnr ,
(source+1+i)->lieferscheinnr ) != 0 )
{
*(dest+j) = *(source+i);
j++;
//found = FALSE;
}

}
// for the last entrie
*(dest+j) = *(source+i);
j++;
tsource->anz = j;

}
The problem with the anz < 1 should be now no problem.

Will this code work ?

And i know that this style *(dest+j) is'nt the best. I will change it
when i have time.

Thanks a lot

ebc

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
55571
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are also removed) So far I have (val is value, ar is array, returns new array):
14
2006
by: Lyle Fairfield | last post by:
d1 and d2 are numbers we can store as doubles (8 bytes). d1 > 0 d2 > 0 d1 < d2 Now s1 and s2 are strings of length 8 bytes. (We can ignore unicode here). Into s1 and s2 we copy the 8 bytes from d1 and d2 respectively.
2
6307
by: Mamatha | last post by:
Hi I have an application with listview.When i click on one button the data will be displayed like this in the listview: colA colB colC ----- ----- ------ nannacom.com 0 0 When i click on another button,i want to display like this
3
5416
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some example first:
10
6771
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a large number) have to be removed (say when ToBeRemoved = true). class SomeObj ToBeRemoved be a boolean field end class
1
2047
by: ericnyc | last post by:
This is my second request. Some how I wrote the first problem I posted. In this assignment I need to print out the sorted array with say 10 entries per line and then Finally it should print out a table consisting of two columns. The first is a list of distinct numbers found and the second is how many times each number occurred in the array How do we do it in C++ Please advise. Thank Eric
3
6439
by: Beholder | last post by:
I hope that someone can help me with the following: Short background explenation: I have a shrfepoint page (newform.aspx) in a item list. On this page is a lookup column that displays a lookup of all category items in previous items. In the code this results in a select/options list like this: <SELECT TABINDEX=1 NAME="urn:schemas-microsoft-com:office:office#CatLookup"><OPTION
9
4909
by: Sheldon | last post by:
Hi, I am trying to understand linked lists and the different ways to write a linked list and double linked list. I have been trying to get this function called insert_word to work but to no avail. The function receives a string from main and then inserts in the list the new word in alphabetical order. Here is my function: struct word { // double linked list. Here the list is global and is first built
36
9185
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have an array of strings. What is the simplest way to remove the elements that are empty, i.e. where the expression "empty($elt)" returns true? Thanks, - Dave
0
9655
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, 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...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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,...
0
9964
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 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...
1
7517
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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();...
0
5398
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...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.