Jump to content

Set (C++)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Minakshinajardhane (talk | contribs) at 05:41, 3 September 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Defination

A set is an associative container data structure that is available as part of the C++ Standard Library (STL), and contains a sorted set of unique objects.[1]

Introduction

Although the abstract concept of a set does not necessarily imply an ordered collection, the standard library set data structure is always ordered. Its functionality in the STL is provided as a template class, such that any valid C++ object can be used with it. Sets are guaranteed to perform operations of insertion, deletion, and testing whether an element is in it, in logarithmic time - O(log n). As such, they are typically implemented using self-balancing binary search trees and support's bidirectional iterator

Types

There are 2 types of sets available in the C++ STL - Sets and Multisets.

Set

Every element is unique and insertions of values that are already present in the container are ignored.

Multiset

In the multiset container however, multiple occurrences of the same value are allowed.

Characteristic

  • Unique element Value :- In a set no two values are same.
  • Element value is itself
  • Elements follow strick weak ordering at all times.

References