૵ (Set)
૵ (Set)

૵ (set) شͧẺ͹حҵ ӡѹ §ӴѺ ֧ա૵Ҫ㹡õǨͺëӢͧ

ҧͧ૵ ѹѻ ͹˹觻 չѡѵ ˹觷ҧԪҡ ª㹨ѧѴ Ҫվ ͪҵ ѭҵ

ҧ : ûС ¡૵ Java
// Set in Java Language
// you can test this code in http://www.ideone.png
Set<Integer> numbers = new TreeSet<Integer>();
numbers.add(2);
numbers.add(5);
System.out.println(numbers); // "[2, 5]"
System.out.println(numbers.contains(7)); // "false"
System.out.println(numbers.contains(5)); // "true"
System.out.println(numbers.add(5)); // "false"
System.out.println(numbers.size()); // "2"
int sum = 0;
for (int n : numbers) { sum += n; }
System.out.println("Sum = " + sum); // "Sum = 7"
numbers.addAll(Arrays.asList(1,2,3,4,5));
System.out.println(numbers); // "[1, 2, 3, 4, 5]"
numbers.removeAll(Arrays.asList(4,5,6,7));
System.out.println(numbers); // "[1, 2, 3]"
numbers.retainAll(Arrays.asList(2,3,4,5));
System.out.println(numbers); // "[2, 3]"
ҧ : ûС ¡૵ Javascript
<!-- Set in Java Language
you can test this code in http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst
code from https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set
-->
<html><head>
<script>
function myset() {
var out = "";
var mySet 
mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add("some text");
mySet.add(6);
out += mySet.has(1); // true
out += mySet.has(3); // false, 3 has not been added to the set
out += mySet.has(5);              // true
out += mySet.has(Math.sqrt(25));  // true
out += mySet.has("Some Text".toLowerCase()); // true
out += mySet.has(6); // true
out += mySet.size; // 4
mySet.delete(5); // removes 5 from the set
out += mySet.has(5);    // false, 5 has been removed
out += mySet.size; // 3, we just removed one value
out += "<br/>";
for (let item of mySet) { out += (item); }
return out;
}
</script>
</head><body>
<button type="button"
onclick="document.getElementById('demo').innerHTML = myset()">Click me</button>
<p id="demo"></p>
</body>
</html> 
programiz.com/python-programming/setprogramiz.com ͸Ժ¤ յҧ IPython Shell 鷴ͺż code .py ҹͧ set A set is an unordered collection of items. Every element is unique (no duplicates) and must be immutable (which cannot be changed). However, the set itself is mutable. We can add or remove items from it. Sets can be used to perform mathematical set operations like union, intersection, symmetric difference etc. build-in function Ѻ set ҷ all(), any(), enumerate(), len(), max(), min(), sorted(), sum()
# set of integers
my_set = {1, 2, 3}
print(my_set)

# set of mixed datatypes
my_set = {1.0, "Hello", (1, 2, 3)}
print(my_set)

# initialize a with {}
a = {}

# check data type of a
# Output: <class 'dict'>
print(type(a))

# initialize a with set()
a = set()

# check data type of a
# Output: <class 'set'>
print(type(a))

# code from programiz.com
͡éѺ (Full Text)

.. ԷٵС

Bruno R. Preiss

Mark Allen Weiss

William H. Ford

DB: Ѳþ

Michael Mcmillan
͡ҧԧ (Reference)
[1] ǧ, "çҧ (Data Structures) ͡͡Ẻ", ѷ प ӡѴ., ا෾, 2549.
[2] Michael McMillan, "Data Structures and Algorithms with JavaScript", OReilly Media, Inc., USA., 2014.
[3] Loiane Groner, "Learning JavaScript Data Structures and Algorithms", Packt Publishing, 2014.

http://goo.gl/72BPC