૵ (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> 
͡éѺ (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.


"Imagination is more important than knowledge" - Albert Einstein
http://goo.gl/72BPC