Click here to Skip to main content
15,922,894 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWhich container should i choose Pin
Shehzad Jamil11-Mar-03 22:29
sussShehzad Jamil11-Mar-03 22:29 
GeneralRe: Which container should i choose Pin
Christian Graus11-Mar-03 22:56
protectorChristian Graus11-Mar-03 22:56 
GeneralRe: Which container should i choose Pin
HJo11-Mar-03 23:08
HJo11-Mar-03 23:08 
GeneralRe: Which container should i choose Pin
markkuk12-Mar-03 0:27
markkuk12-Mar-03 0:27 
GeneralRe: Which container should i choose Pin
Tim Smith12-Mar-03 1:59
Tim Smith12-Mar-03 1:59 
GeneralRe: Which container should i choose Pin
Alexandru Savescu12-Mar-03 5:54
Alexandru Savescu12-Mar-03 5:54 
GeneralRe: Which container should i choose Pin
Tim Smith12-Mar-03 8:12
Tim Smith12-Mar-03 8:12 
GeneralRe: Which container should i choose Pin
atreya12-Mar-03 6:35
atreya12-Mar-03 6:35 
Hello,

STL 'std::set' best suits Eek! | :eek: your application based on what you have explained.

'std::set' STL has been particularly designed to hold unique elements of a particular datatype. As your container needs to hold only unique valuesOMG | :OMG: , you can exploit the 'std::set' STL efficiently. It will also work faster and more efficiently that a vector implementation for your usage since a 'std::set' is specially designed to hold unique elements and a customized find() function exists for 'std::set' that you can use instead of using the generic 'find()' function. This also adds to efficiency.Smile | :)

I've given a small code snippet here for you:Rose | [Rose]

-------------------------------------------------
#include <set>
#include <iostream>

using namespace std;

int main()
{
	set<int> set1;

	// insert 10 integers.
	for(int i = 0; i < 10; ++i)
		set1.insert(i);

	cout << "Set contains: ";
	for(set<int>::iterator set_iter = set1.begin(); set_iter != set1.end(); ++set_iter)
		cout << *set_iter << " ";
	cout << endl << endl;

	int value_to_be_searched = 5;
	
	set<int>::iterator si = set1.find(value_to_be_searched);
	if(si != set1.end())
		cout << "Value " << value_to_be_searched << ": found!!" << endl;
	else
		cout << "Value " << value_to_be_searched << ": not found!!" << endl;

	value_to_be_searched = 14;

	si = set1.find(value_to_be_searched);
	if(si != set1.end())
		cout << "Value " << value_to_be_searched << ": found!!" << endl;
	else
		cout << "Value " << value_to_be_searched << ": not found!!" << endl;

	return 0;
}


-------------------------------------------------

Bye,
Chaitanya Atreya.


Whenever I hear someone sighing "Life is hard",
I'm tempted to ask "Compared to what?".
GeneralRe: Ok, I geeked out Pin
Tim Smith12-Mar-03 8:08
Tim Smith12-Mar-03 8:08 
GeneralBarcode generator Pin
Chintan11-Mar-03 21:14
Chintan11-Mar-03 21:14 
GeneralRe: Barcode generator Pin
Johnny ²11-Mar-03 21:36
Johnny ²11-Mar-03 21:36 
GeneralRe: Barcode generator Pin
Chintan12-Mar-03 21:38
Chintan12-Mar-03 21:38 
QuestionSockets - recv - Number of received bytes? Pin
Daniel Strigl11-Mar-03 20:59
Daniel Strigl11-Mar-03 20:59 
AnswerRe: Sockets - recv - Number of received bytes? Pin
valikac11-Mar-03 21:17
valikac11-Mar-03 21:17 
AnswerRe: Sockets - recv - Number of received bytes? Pin
Johnny ²11-Mar-03 21:40
Johnny ²11-Mar-03 21:40 
AnswerRe: Sockets - recv - Number of received bytes? Pin
Tim Smith12-Mar-03 2:03
Tim Smith12-Mar-03 2:03 
AnswerRe: Sockets - recv - Number of received bytes? Pin
Joseph Dempsey13-Mar-03 8:20
Joseph Dempsey13-Mar-03 8:20 
GeneralRe: Sockets - recv - Number of received bytes? Pin
Daniel Strigl13-Mar-03 8:34
Daniel Strigl13-Mar-03 8:34 
General"OnChar" Msg and Edit Control Pin
Gabor Kalman11-Mar-03 20:59
Gabor Kalman11-Mar-03 20:59 
GeneralRe: "OnChar" Msg and Edit Control Pin
Brian Shifrin12-Mar-03 0:34
Brian Shifrin12-Mar-03 0:34 
GeneralRe: "OnChar" Msg and Edit Control Pin
Gabor Kalman12-Mar-03 12:44
Gabor Kalman12-Mar-03 12:44 
GeneralMAPI problem Pin
chepuri_uk11-Mar-03 20:39
chepuri_uk11-Mar-03 20:39 
GeneralTimer problems Pin
Dennis Kuppens11-Mar-03 20:17
Dennis Kuppens11-Mar-03 20:17 
GeneralRe: Timer problems Pin
KarstenK11-Mar-03 20:44
mveKarstenK11-Mar-03 20:44 
GeneralHelp..Help...!!!!!!!! Pin
Renjith Ramachandran11-Mar-03 19:21
Renjith Ramachandran11-Mar-03 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.