home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!mickey!bsmith
- From: bsmith@mickey.NoSubdomain.NoDomain (Brian Smith)
- Newsgroups: comp.programming
- Subject: Re: Locating duplicates
- Date: 5 Jan 1993 07:12:55 GMT
- Organization: University of California, Berkeley
- Lines: 37
- Sender: bsmith@mickey (Brian Smith)
- Distribution: world
- Message-ID: <1ibcdnINNpb1@agate.berkeley.edu>
- References: <1993Jan2.041658.21596@organpipe.uug.arizona.edu> <DOUGM.93Jan2014723@titan.cs.rice.edu> <C07z6L.1Aq@world.std.com> <1993Jan5.043456.29130@micor.ocunix.on.ca>
- NNTP-Posting-Host: mickey.cs.berkeley.edu
-
- In article <1993Jan5.043456.29130@micor.ocunix.on.ca>, goss@micor.ocunix.on.ca (Timothy D. Goss) writes:
- |> You can locate ALL duplicates in a list of integers with a single pass of the
- |> list which is O(n) in time but it will require an array with 64K elements. The
- |> program below should explain...
- |>
- |> typedef unsigned char byte;
- |>
- |> static byte found[65536];
- |> int intlist[NUM];
- |>
- |> void main(void)
- |> {
- |>
- |> int i;
- |> int check;
- |>
- |> /* assume intlist is filled with NUM integers */
- |>
- |> for (i=0; i<NUM; i++) {
- |> check = intlist[i];
- |> if (found[check] > 0 && found[check] != 0xff) {
- |> printf("%d\n", check);
- |> found[check] = 0xff; /* don't report same dupe twice */
- |> } else {
- |> found[check] += 1; /* first time we saw this one */
- |> }
- |> }
- |>
- |> }
-
- Uh, maybe I'm really missing something, but won't this crash and burn and
- core-dump if the integers are > 16 bits? Don't try this on an alpha...
-
- -------
- Brian C. Smith arpa: bsmith@cs.Berkeley.EDU
- University of California, Berkeley uucp: uunet!ucbvax!postgres!bsmith
- Computer Sciences Department phone: (510)642-9585
-