Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   setUnion(), setIntersection() (https://forums.graalonline.com/forums/showthread.php?t=76540)

coreys 08-28-2007 06:47 AM

setUnion(), setIntersection()
 
Here's two functions I made out of boredom from something I learned in about in math today.
PHP Code:

public function setUnion(set1set2) {
  
temp.set set1;
  for (
i=0i<set2.size(); i++) {
    if (!
set2[iin set1)
      
temp.set.add(set2[i]);
  }
  
temp.set.sortascending();
  return 
temp.set;
}
public function 
setIntersection(set1set2) {
  
temp.set NULL;
  for (
i=0i<set2.size(); i++) {
    if (
set2[iin set1)
      
temp.set.add(set2[i]);
  }
  
temp.set.sortascending();
  return 
temp.set;


If you didn't know, sets are pretty much arrays. setUnion(set1, set2) essentially combines two arrays, and setIntersection(set1, set2) makes an array of values that are in both sets (arrays).

Chompy 08-28-2007 04:17 PM

Hmm, nice Vash :p


All times are GMT +2. The time now is 10:32 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.