Sets are a very efficient data structure to store a common group of values like a vector may, but one of the key differences is that a set doesn’t contain duplicates.
std::set. std::set is an associative container that contains a sorted set of unique objects of type Key. Sorting is done using the key comparison function Compare.
The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.
In this article, we will dive into the world of sets, which are powerful data structures that allow you to store and manipulate unique elements efficiently.
Elements of a set are referenced using their key , not by their position in the container. This is unlike arrays , where elements are accessed using indexes.
To define a set, first use the STL set, and then, in the angle brackets < >, specify the data type of the set elements and, after that, the set's name.
Standard and Strict subset and superset checks. Simple method to change the hashing function if desired. Add, check, and remove elements in a the set. ... cset.
Get ve Set Neden Kullanılır? Bir class veya struct içerisinde private olarak oluşturulan bir öğeye o class veya struct dışından erişmek mümkün değildir.
. It's true that .NET doesn't cater for sets as well as Java does though.The Wintellect PowerCollections may help too.
17 Temmuz 2023
451 kişi değerlendirdi
9 yorum
{"2_b58s":{"state":{"logo":{"href":"//yandex.com.tr","isForeign":true},"form":{"action":"/search/","searchLabel":"Bul","hiddenInputs":[{"name":"lr","value":20815}]},"actions":{"advancedSearch":{"checked":false,"ariaLabel":"Gelişmiş arama"},"moreButtonProps":{"ariaLabel":"Daha fazla"},"cbir":{"name":"cbir","label":"Görsele göre arama","infoUrl":"//yandex.ru/promo/photosearch/index?source=landingdesk","isMacOS":false}},"userSection":{"loggedIn":false,"loginProps":{"loginUrl":"https://passport.yandex.com.tr/auth?retpath=%2F&origin=serp_desktop_auth_new","loginText":"Giriş yap","burgerAriaLabel":"Menü"}},"navigation":{"tabs":[{"id":"www","label":"Arama","url":"//yandex.com.tr","params":{"source":"tabbar"},"target":""},{"id":"images","label":"Görsel","url":"//yandex.com.tr/gorsel/search","params":{"text":"[$query]","noreask":"[$noreask]","nomisspell":"[$nomisspell]","parent-reqid":"[$reqid]","from":"tabbar"}},{"id":"video","label":"Video","url":"//yandex.com.tr/video/search","params":{"text":"[$query]","noreask":"[$noreask]","parent-reqid":"[$reqid]","from":"tabbar"}},{"id":"maps","label":"Haritalar","url":"//yandex.com.tr/harita","params":{"text":"[$query]","source":"serp_navig"}},{"id":"translate","label":"Çeviri","url":"//ceviri.yandex.com.tr","params":{"text":"[$query]","from":"tabbar"}}],"selectedTabId":"www"},"context":{"query":"set c","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL","lr":"20815","counters":{"type":"b","data":{"$header":"0_hizkz000","logo":"0_hizkz001","login":"0_hizkz003","usermenu":"0_hizkz004","market-cart":"0_hizkz006","more-button":"0_hizkz007","cbir":"0_hizkz008","$navigation":"0_hizkz009","item":"0_hizkz00i","tab-www":"0_hizkz00b","tab-images":"0_hizkz00d","tab-video":"0_hizkz00f","tab-maps":"0_hizkz00h","tab-translate":"0_hizkz00j"}}},"loggedIn":false,"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"0_hizkw01-0-1"},"ui":"desktop","service":"web","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL","fast":{"name":"header-desktop"}}}}},"type":"header-desktop"},"2_hizk0":{"state":{"answersUrl":"https://stackoverflow.com/questions/183685/c-sharp-set-collection#answers","type":"fact","tabsOptions":[{"id":"question","text":"Soru"},{"id":"bestAnswer","text":"En iyi yanıt"},{"id":"moreAnswers","text":"6 yanıt daha","shortText":"Daha fazla"}],"tabContents":{"question":{"construct":[{"type":"paragraph","content":[{"type":"text","content":"Does anyone know if there is a good equivalent to Java's "},{"type":"code","content":[{"type":"text","content":"Set"}],"isInline":true},{"type":"text","content":" collection in C#? I know that you can somewhat mimic a set using a "},{"type":"code","content":[{"type":"text","content":"Dictionary"}],"isInline":true},{"type":"text","content":" or a "},{"type":"code","content":[{"type":"text","content":"HashTable"}],"isInline":true},{"type":"text","content":" by populating but ignoring the values, but that's not a very elegant way. "}]}],"footerProps":{"date":1377152016,"numLiked":573,"numCommented":0}},"bestAnswer":{"construct":[{"type":"paragraph","content":[{"type":"text","content":"If you're using .NET 3.5, you can use "},{"type":"code","content":[{"type":"text","content":"HashSet\u003cT>"}],"isInline":true},{"type":"text","content":". It's true that .NET doesn't cater for sets as well as Java does though."}]},{"type":"paragraph","content":[{"type":"text","content":"The "},{"type":"text","content":"Wintellect PowerCollections"},{"type":"text","content":" may help too."}]}],"footerProps":{"date":1689600578,"numLiked":451,"numCommented":9}},"moreAnswers":[{"construct":[{"type":"paragraph","content":[{"type":"text","content":"Try "},{"type":"text","content":"HashSet"},{"type":"text","content":":"}]},{"type":"paragraph","content":[{"type":"text","content":"The HashSet(Of T) class provides high-performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order..."}]},{"type":"paragraph","content":[{"type":"text","content":"The capacity of a HashSet(Of T) object is the number of elements that the object can hold. A HashSet(Of T) object's capacity automatically increases as elements are added to the object."}]},{"type":"paragraph","content":[{"type":"text","content":"The HashSet(Of T) class is based on the model of mathematical sets and provides high-performance set operations similar to accessing the keys of the "},{"type":"text","content":"Dictionary(Of TKey, TValue)"},{"type":"text","content":" or "},{"type":"text","content":"Hashtable"},{"type":"text","content":" collections. In simple terms, the HashSet(Of T) class can be thought of as a "},{"type":"text","content":"Dictionary(Of TKey, TValue)"},{"type":"text","content":" collection without values."}]},{"type":"paragraph","content":[{"type":"text","content":"A HashSet(Of T) collection is not sorted and cannot contain duplicate elements..."}]}],"footerProps":{"date":1475342779,"numLiked":189,"numCommented":1}},{"construct":[{"type":"paragraph","content":[{"type":"text","content":"If you're using .NET 4.0 or later:"}]},{"type":"paragraph","content":[{"type":"text","content":"In the case where you need sorting then use "},{"type":"code","content":[{"type":"text","content":"SortedSet\u003cT>"}],"isInline":true},{"type":"text","content":". Otherwise if you don't, then use "},{"type":"code","content":[{"type":"text","content":"HashSet\u003cT>"}],"isInline":true},{"type":"text","content":" since it's "},{"type":"code","content":[{"type":"text","content":"O(1)"}],"isInline":true},{"type":"text","content":" for search and manipulate operations. Whereas "},{"type":"code","content":[{"type":"text","content":"SortedSet\u003cT>"}],"isInline":true},{"type":"text","content":" is "},{"type":"code","content":[{"type":"text","content":"O(log n)"}],"isInline":true},{"type":"text","content":" for search and manipulate operations."}]}],"footerProps":{"date":1377973023,"numLiked":37,"numCommented":0}}]},"organic":{"faviconProps":{"src":"https://favicon.yandex.net/favicon/v2/https://stackoverflow.com","size":"m","pageNumber":0,"index":0},"title":"\u0007[C\u0007]# \u0007[Set\u0007] collection?","pathProps":{"items":[{"url":"https://stackoverflow.com/questions/183685/c-sharp-set-collection","text":"stackoverflow.com"},{"url":"https://stackoverflow.com/questions/183685/c-sharp-set-collection","text":"c-sharp-set-collection"}]},"faviconPosition":0,"subtitlePosition":1,"linkProps":{"url":"https://stackoverflow.com/questions/183685/c-sharp-set-collection"},"hostTitle":"Stackoverflow.com","description":"stackoverflow.com › c-sharp-set-collection"},"extralinksProps":{"hidden":true,"directions":["bottom-end"],"items":[{"variant":"reportFeedback","reportFeedback":{"feature":"Блок ответов для разработчиков","title":"Bu yanıtta yanlış olan nedir?","checkBoxLabels":[{"value":"Yanıt sorguya uygun değil"},{"value":"Yanıt hatalı"},{"value":"Yanıttaki bilgiler eksik"},{"value":"Diğer"}]}}]},"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_hizkw0g-0-1"},"ui":"desktop","service":"web","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL","fast":{"name":"article"}}}}},"type":"article"},"2_hizk1":{"state":{"linksGroups":[{"type":"geo","links":[{"label":"Columbus","title":"Columbus","url":"//yandex.com.tr/tune/geo","logNode":{"name":"region"},"target":"_self","a11yLabel":"Bölgeniz Columbus","needRetpath":true}]},{"type":"feedback","links":[{"label":"Hata bildir","logNode":{"name":"feedback","attrs":{"behaviour":{"type":"dynamic"}}}}]},{"type":"settings","links":[{"label":"Ayarlar","url":"//yandex.com.tr/tune/search","logNode":{"name":"settings"},"target":"_self","needRetpath":true}]},{"type":"company","links":[{"label":"Hakkımızda","url":"https://company.yandex.com.tr","logNode":{"name":"about"},"target":"_blank"},{"label":"Ticari teklifler","url":"/search/direct?text=set%20c&filters_docs=direct_cm","logNode":{"name":"commercial"},"target":"_blank"},{"label":"Kariyer","url":"//yandex.com.tr/jobs/?utm_source=serp_turkie&utm_medium=footerlink&utm_content=career","logNode":{"name":"vacancy"},"target":"_blank"},{"label":"Kullanım lisansı","url":"//yandex.com.tr/legal/termsofuse/","logNode":{"name":"license"},"target":"_blank"},{"label":"Gizlilik Politikası","url":"//yandex.com.tr/legal/confidential/","logNode":{"name":"confidential"},"target":"_blank"}],"a11yHidden":true}],"reportFeedbackProps":{"feature":"Подвал","title":"Hata bildir","checkBoxLabels":[]},"isSearchApp":false,"hasExtralinks":true,"limitingSelector":".AliceFabButton","baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_hizkw0h-0-1"},"ui":"desktop","service":"web","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL"}}}},"type":"serp-footer"},"2_hizk2":{"state":{"conditionLoadList":{"marketCart":false,"highchartsHighstock":false,"advProductGallery":false,"musicPlayer":false,"ecomRates":false,"photoViewer":false,"easterEggModal":false,"easterEggPlusGamesModal":false,"futurisFeedbackLoader":false,"darkmodeChangeDrawer":true},"reportFeedbackBaseProps":{"initEmail":"","metaFields":{"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","userTestids":"554938,186144,151171,126351,1106126,1069988,13962,287509,338390,1112645,785124,1103876,1115375,1112004,1102157,1091205,1109998,1114540,1101545,1082996,1104159,1092851,1110310,912285","yandexuid":"6849433551726600248","uid":"0","queryText":"set c","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL","searchSlices":["drawer_search_slice_cs"],"userRegionName":"Columbus","userRegionId":"20815","isChildAccount":false}},"extralinksPopupProps":{"abuseLink":"https://twitter.yandex.com.tr/search/abuse?sign=4ece018516918e79ced728b2b855c72f&keyno=0"},"isLoggedIn":false,"userMenuDialogProps":{"flag":"skin,feedback","host":"yandex.com.tr","lang":"tr","project":"serp","queryParams":{"utm_source":"search"},"retpath":"https%3A%2F%2Ftwitter.yandex.com.tr%2Fsearch%2F%3Ffilters_docs%3Ddirect_cm%26lr%3D20815%26text%3Dset%2Bc%26ncrnd%3D39931","tld":"com.tr"},"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_hizkw0i-0-1"},"ui":"desktop","service":"web","reqid":"1726600248577044-9909084652784943355-balancer-l7leveler-kubr-yp-sas-264-BAL","fast":{"name":"lazy-load"}}}}},"type":"lazy-load"}}