Click here to Skip to main content
15,885,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 14:20
Stephen Hewitt1-Jun-06 14:20 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
George_George1-Jun-06 18:45
George_George1-Jun-06 18:45 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 18:54
Stephen Hewitt1-Jun-06 18:54 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
George_George1-Jun-06 19:06
George_George1-Jun-06 19:06 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 19:21
Stephen Hewitt1-Jun-06 19:21 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
George_George1-Jun-06 20:13
George_George1-Jun-06 20:13 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 20:17
Stephen Hewitt1-Jun-06 20:17 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 18:57
Stephen Hewitt1-Jun-06 18:57 
He's a version which sorts the array in-place without using a vector:

#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

const char* g_Names1[] = {"Joe", "Paul", "Simon", "Steve", "Karl"};
const char** g_Names1Begin = &g_Names1[0];
const char** g_Names1End = &g_Names1[sizeof(g_Names1)/sizeof(g_Names1[0])];

const char* g_Names2[] = {"Paul", "Kate", "Oleg"};
const char** g_Names2Begin = &g_Names2[0];
const char** g_Names2End = &g_Names2[sizeof(g_Names2)/sizeof(g_Names2[0])];

struct CharLess
{
bool operator()(const char* p1, const char* p2) const
{
return strcmp(p1, p2)<0;
}
};

int main(int argc, char* argv[])
{
sort(g_Names1Begin, g_Names1End, CharLess());
sort(g_Names2Begin, g_Names2End, CharLess());
set_intersection(
g_Names1Begin, g_Names1End,
g_Names2Begin, g_Names2End,
ostream_iterator<const char*>(cout, "\n"),
CharLess()
);

return 0;
}


Steve
GeneralRe: how to compute set intersection efficiently? [modified] Pin
George_George1-Jun-06 19:09
George_George1-Jun-06 19:09 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
Stephen Hewitt1-Jun-06 19:22
Stephen Hewitt1-Jun-06 19:22 
GeneralRe: how to compute set intersection efficiently? [modified] Pin
George_George1-Jun-06 20:16
George_George1-Jun-06 20:16 
QuestionLast Window Message [modified] Pin
HakunaMatada31-May-06 21:12
HakunaMatada31-May-06 21:12 
AnswerRe: Last Window Message Pin
Michael Dunn31-May-06 21:13
sitebuilderMichael Dunn31-May-06 21:13 
GeneralRe: Last Window Message Pin
HakunaMatada31-May-06 21:18
HakunaMatada31-May-06 21:18 
QuestionVisual C++.NET and VS C++ 6.0, are they the same? Pin
DzungLean31-May-06 21:07
DzungLean31-May-06 21:07 
AnswerRe: Visual C++.NET and VS C++ 6.0, are they the same? Pin
Michael Dunn31-May-06 21:12
sitebuilderMichael Dunn31-May-06 21:12 
AnswerRe: Visual C++.NET and VS C++ 6.0, are they the same? Pin
toxcct31-May-06 23:04
toxcct31-May-06 23:04 
AnswerRe: Visual C++.NET and VS C++ 6.0, are they the same? Pin
William.Wang31-May-06 23:09
William.Wang31-May-06 23:09 
QuestionHow end/stop/destroy a thread Pin
zahid_ash31-May-06 20:56
zahid_ash31-May-06 20:56 
AnswerRe: How end/stop/destroy a thread Pin
Stephen Hewitt31-May-06 21:11
Stephen Hewitt31-May-06 21:11 
Generalwould this stop release the memory occupied by a thread Pin
zahid_ash31-May-06 21:17
zahid_ash31-May-06 21:17 
AnswerRe: How end/stop/destroy a thread Pin
Cedric Moonen31-May-06 21:11
Cedric Moonen31-May-06 21:11 
AnswerRe: How end/stop/destroy a thread [modified] Pin
_AnsHUMAN_ 31-May-06 22:01
_AnsHUMAN_ 31-May-06 22:01 
AnswerRe: How end/stop/destroy a thread Pin
David Crow1-Jun-06 4:07
David Crow1-Jun-06 4:07 
QuestionCString to char* conversion Pin
NiceNaidu31-May-06 20:34
NiceNaidu31-May-06 20:34 

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.