🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #189

Need help (short)

#189
From: Sam Sutherland
Date: Sun, 25 Apr 1999 00:00
54 lines
1870 bytes
Basically I need to compare an element to a set, for purposes of Difference.
Right now, I can add and compare sets, but not an element to a set. I need
to computer the difference of two sets: elements in set1 but not set2. Here
is what I have for Union. Can anybody can manipulate this code into
Difference? I have it working for ints, doubles, and strings. It should be
simple. Thanks- samantha

template <class T>
Set<T> & Set<T>::setUnion(Set<T> & b)
{
static Set<T> c;
c = *this;
for(int j = 0; j < b.size; j++)
{
  bool flag=true;
  for(int k = 0; k < c.size; k++)
   if(b.container[j] == c.container[k])
   {
    flag = false;
    break;
   }
  if(flag == true)
   c.container[c.size++] = b.container[j];
}
return c;
}
//template <class T>
Set<char *> & Set<char *>::setUnion(Set<char *> & b)
{
static Set<char *> c;
c = *this;
for(int k = 0; k < size; k++)
{
  c.container[k] = new char[strlen(container[k])+1];
  strcpy(c.container[k], container[k]);
}
c.size = k;
  for(int j = 0; j < b.size; j++)
{
  bool flag=true;
  for(int k = 0; k < c.size; k++)
   if(strcmp(b.container[j],c.container[k]) == 0)
   {
    flag = false;
    break;
   }
  if(flag == true)
  {
   c.container[c.size] =
    new char [strlen(b.container[j])+ 1];
   strcpy(c.container[c.size++],b.container[j]);
  }
}
return c;
Technical Details
Message-ID: <7g0ctf$fi$1@autumn.news.rcn.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,1107d09da35771f,start
X-Google-Attributes: gid10d4ba,public
From: "Sam Sutherland" <samantha_sutherl@hotmail.com>
Subject: Need help (short)
Date: 1999/04/25
Message-ID: <7g0ctf$fi$1@autumn.news.rcn.net>
X-Deja-AN: 470856258
X-Trace: C+iqFBqR3g2uvYYfzyDOid9Mf7MFoQAp+SaGpvFTg/0=
NNTP-Posting-Date: 26 Apr 1999 00:44:31 GMT
Newsgroups: att.lang.c++
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: abuse@rcn.com