25.07.2017 Views

Intro-CSharp-Book-v2015

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

768 Въведение в програмирането със C#<br />

/// Performs intersection of this set with the specified set<br />

/// <br />

/// Set to intersect with<br />

public void IntersectWith(TreeSet other)<br />

{<br />

List elementsToRemove =<br />

new List(Math.Min(this.Count, other.Count));<br />

foreach (T key in this.innerDictionary.Keys)<br />

{<br />

if (!other.Contains(key))<br />

{<br />

elementsToRemove.Add(key);<br />

}<br />

}<br />

}<br />

foreach (T elementToRemove in elementsToRemove)<br />

{<br />

this.Remove(elementToRemove);<br />

}<br />

/// <br />

/// Performs an union operation with another set<br />

/// <br />

/// The set to perform union with<br />

public void UnionWith(TreeSet other)<br />

{<br />

foreach (T key in other)<br />

{<br />

this.innerDictionary[key] = true;<br />

}<br />

}<br />

#region ICollection Members<br />

void ICollection.Add(T item)<br />

{<br />

this.Add(item);<br />

}<br />

public void Clear()<br />

{<br />

this.innerDictionary.Clear();<br />

}<br />

public bool Contains(T item)<br />

{<br />

return this.innerDictionary.ContainsKey(item);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!