🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Sam Sutherland Sun, 25 Apr 1999 00:00
Need help (short)
#189
Author: 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;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads