Book Image

Everyday data structures

By : William Smith
Book Image

Everyday data structures

By: William Smith

Overview of this book

Explore a new world of data structures and their applications easily with this data structures book. Written by software expert William Smith, you?ll learn how to master basic and advanced data structure concepts. ? Fully understand data structures using Java, C and other common languages ? Work through practical examples and learn real-world applications ? Get to grips with data structure problem solving using case studies
Table of Contents (20 chapters)
Everyday Data Structures
About the Author
About the Reviewer
Customer Feedback
Free Chapter
Data Types: Foundational Structures

Initializing sets

Sets are not terribly commonplace in development, but each of the languages we are examining supports data structures with some form of concrete implementations. Here are some examples of initializing a set, adding a few values to the collection including one duplicate, and printing the set's count to the console after each step.


C# provides a concrete implementation of the set data structure through the HashSet<T> class. Since this class is generic, the caller may define the type used for elements. For example, the following example initializes a new set where the elements will be string types:

    HashSet<string, int> mySet = new HashSet<string>(); 
    Console.WriteLine("{0}", mySet.Count); 
    Console.WriteLine("{0}", mySet.Count); 
    Console.WriteLine("{0}", mySet.Count); 
    Console.WriteLine("{0}", mySet...