Announcement

Collapse
No announcement yet.

arbeiten mit bitoperatoren und mengen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • arbeiten mit bitoperatoren und mengen

    hallo,

    ich sitze hier vor einem problem. ich habe 3 variablen des typs int, die mengen darstellen sollen. nun habe ich diverse funktionen vordefiniert, die ich nur noch füllen muss, komme hier aber nicht ganz weiter:

    <PRE>
    /*------------------------------------------------------------*/
    /**
    * Function isetIsEmpty(int theSet) returns true whenever
    * the set 'theSet' is empty.
    */
    static boolean isetIsEmpty(int theSet)
    {
    if (theSet == 0)
    return true;
    else
    return false;
    }

    /*------------------------------------------------------------*/
    /**
    * Function isetInsertElement(int theElement, int theSet)
    * inserts an element 'theElement' into the set 'theSet'
    * and returns the resulting set.
    */
    static int isetInsertElement(int theElement, int theSet)
    {
    return theSet = theSet | (1 << theElement);
    }

    /*------------------------------------------------------------*/
    /**
    * Function isetUnion(int set1, int set2)
    * returns the set union of sets 'set1' and 'set2'.
    */
    static int isetUnion(int set1, int set2)
    {
    return set1 | set2;
    }

    /*------------------------------------------------------------*/
    /**
    * Function isetDiff(int set1, int set2)
    * returns the set difference of sets 'set1' and 'set2',
    * i.e. 'set1' \ 'set2'
    */
    static int isetDiff(int set1, int set2)
    {
    return set1 - set2;
    }

    /*------------------------------------------------------------*/
    /**
    * Function isetIntersection(int set1, int set2)
    * returns the set intersection of sets 'set1' and 'set2'.
    */
    static int isetIntersection(int set1, int set2)
    {
    return set1 & set2;
    }

    /*------------------------------------------------------------*/
    /**
    * Function isetPrint(int theSet, String theSetsName)
    * prints all elements of 'theSet' together with the string
    * 'theSetsName' (for identification purposes).
    */
    static void isetPrint(int theSet, String theSetsName)
    {
    System.out.println(theSetsName + ": " + theSet);
    }

    /*------------------------------------------------------------*/</PRE>

    Ich habe die funktionen bereits mit code gefüllt, bin aber nicht der meinung das dieser richtig ist. kann sich vielleicht wer meine funktionen ansehen und mir sagen ob diese richtig sind, bzw., korrigieren? das wäre sehr nett.

    bye dermold
Working...
X