Click here to Skip to main content
15,909,039 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What's the difference? Pin
Christian Graus4-Aug-01 11:43
protectorChristian Graus4-Aug-01 11:43 
GeneralRe: What's the difference? Pin
Ben Burnett4-Aug-01 12:00
Ben Burnett4-Aug-01 12:00 
GeneralRe: Gloabl variabl, reference & pointer. Pin
Masaaki Onishi5-Aug-01 6:27
Masaaki Onishi5-Aug-01 6:27 
GeneralRe: What's the difference? Pin
Joe Woodbury5-Aug-01 9:03
professionalJoe Woodbury5-Aug-01 9:03 
Generallinked list with fast sorting Pin
4-Aug-01 4:17
suss4-Aug-01 4:17 
GeneralRe: linked list with fast sorting Pin
Christian Graus4-Aug-01 11:41
protectorChristian Graus4-Aug-01 11:41 
GeneralRe: linked list with fast sorting Pin
6-Aug-01 0:12
suss6-Aug-01 0:12 
GeneralRe: linked list with fast sorting Pin
Malcolm McMahon6-Aug-01 2:40
Malcolm McMahon6-Aug-01 2:40 
A simple list is inherently slow to search, because you can only go through sequentially. Your best bet is probably a binary tree (though it depends how your data is organised before loading. Simple binary trees are a disaster if your data is allready sorted).

If your data is loaded in order, use a straight array and search with a binary chop.

If your data is loaded at random use a binary tree. Building a binary tree is pretty trivial if you don't care about balancing (required for optimal search times).

<br />
class CMyNode {<br />
  char *key;  // assuming text key, otherwise modify comparison<br />
...<br />
...<br />
  CMyNode *children[2];  // children[0] is lower keys children[1] is higher<br />
<br />
  static CMyNode *root;<br />
<br />
  CMyNode(...)<br />
  static CMyNode *find(const char *);<br />
};<br />
<br />
CMyNode::CMyNode( ... ) {<br />
<br />
   ...<br />
<br />
   CMyNode *p,**pp = &root;<br />
   while((p = *pp) != NULL) {<br />
     int cmp = strcmp(key, p->key);<br />
     if(cmp == 0) {<br />
       .. duplicate (Error? )<br />
      } else<br />
     pp = &p->children[cmp < 0 ? 0 : 1];<br />
     }<br />
   *pp = this;<br />
   children[0] = NULL;<br />
   children[1] = NULL;<br />
  <br />
   ..<br />
   }<br />
<br />
CMyNode CMyNode::find(const char *key) {<br />
   CMyNode *p;<br />
   int cmp;<br />
<br />
   for(p = root; p; p = p->children[cmp < 0]) {<br />
     cmp = strcmp(key, p->key);<br />
     if(!cmp)<br />
        return p;<br />
     }<br />
   return NULL;<br />
   }<br />

GeneralRe: linked list with fast sorting Pin
6-Aug-01 4:08
suss6-Aug-01 4:08 
GeneralRe: linked list with fast sorting Pin
Malcolm McMahon6-Aug-01 5:09
Malcolm McMahon6-Aug-01 5:09 
GeneralRe: linked list with fast sorting Pin
7-Aug-01 1:09
suss7-Aug-01 1:09 
GeneralThread Client\Serveur Pin
4-Aug-01 4:16
suss4-Aug-01 4:16 
GeneralRe: Thread Client\Serveur Pin
4-Aug-01 4:19
suss4-Aug-01 4:19 
GeneralRe: Thread Client\Serveur Pin
Baafie4-Aug-01 14:29
Baafie4-Aug-01 14:29 
GeneralAutomating Project Creation Pin
Steve Thresher4-Aug-01 1:52
Steve Thresher4-Aug-01 1:52 
GeneralRe: Automating Project Creation Pin
Steve Thresher4-Aug-01 2:45
Steve Thresher4-Aug-01 2:45 
GeneralRe: Automating Project Creation Pin
Steve Thresher4-Aug-01 2:48
Steve Thresher4-Aug-01 2:48 
GeneralScrolling a Bitmap in a CScrollView Pin
baywa4-Aug-01 1:13
baywa4-Aug-01 1:13 
GeneralCRichEditView::Stream() Pin
Frank Deo4-Aug-01 0:20
Frank Deo4-Aug-01 0:20 
GeneralRe: CRichEditView::Stream() Pin
Baafie4-Aug-01 2:59
Baafie4-Aug-01 2:59 
GeneralRe: CRichEditView::Stream() Pin
Frank Deo4-Aug-01 9:55
Frank Deo4-Aug-01 9:55 
GeneralRe: CRichEditView::Stream() Pin
4-Aug-01 12:46
suss4-Aug-01 12:46 
GeneralRe: CRichEditView::Stream() Pin
Frank Deo5-Aug-01 4:20
Frank Deo5-Aug-01 4:20 
Questionhow to Delete a class in visual c++? Pin
nemati3-Aug-01 21:28
nemati3-Aug-01 21:28 
AnswerRe: how to Delete a class in visual c++? Pin
Christian Graus4-Aug-01 2:40
protectorChristian Graus4-Aug-01 2:40 

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.