Click here to Skip to main content
15,891,859 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Hi Pin
David Crow19-May-09 2:40
David Crow19-May-09 2:40 
AnswerRe: Hi Pin
Mohammadj20-May-09 22:24
Mohammadj20-May-09 22:24 
QuestionRe: Hi Pin
David Crow21-May-09 2:50
David Crow21-May-09 2:50 
QuestionBigNum Pin
AndreFratelli11-May-09 2:51
AndreFratelli11-May-09 2:51 
QuestionRe: BigNum Pin
Divyang Mithaiwala11-May-09 3:35
Divyang Mithaiwala11-May-09 3:35 
AnswerRe: BigNum Pin
harold aptroot11-May-09 4:05
harold aptroot11-May-09 4:05 
QuestionRe: BigNum Pin
David Crow11-May-09 4:39
David Crow11-May-09 4:39 
QuestionRe: BigNum Pin
CPallini11-May-09 5:13
mveCPallini11-May-09 5:13 
QuestionUnable to Install Plateform SDK Pin
pandit8411-May-09 2:20
pandit8411-May-09 2:20 
AnswerRe: Unable to Install Plateform SDK Pin
Naveen11-May-09 2:25
Naveen11-May-09 2:25 
GeneralRe: Unable to Install Plateform SDK Pin
pandit8411-May-09 3:45
pandit8411-May-09 3:45 
GeneralRe: Unable to Install Plateform SDK Pin
Naveen11-May-09 3:51
Naveen11-May-09 3:51 
Questionwmi problem Pin
Mogaambo11-May-09 2:19
Mogaambo11-May-09 2:19 
AnswerRe: wmi problem Pin
«_Superman_»11-May-09 2:35
professional«_Superman_»11-May-09 2:35 
Questionbuild errors Pin
josip cagalj11-May-09 1:36
josip cagalj11-May-09 1:36 
AnswerRe: build errors Pin
josip cagalj11-May-09 2:26
josip cagalj11-May-09 2:26 
QuestionHow to compress an image? Pin
kapardhi11-May-09 1:30
kapardhi11-May-09 1:30 
AnswerRe: How to compress an image? Pin
CPallini11-May-09 1:41
mveCPallini11-May-09 1:41 
AnswerRe: How to compress an image? Pin
Stuart Dootson11-May-09 6:00
professionalStuart Dootson11-May-09 6:00 
QuestionSkip list takes so much time in insertion Pin
Risa Harada11-May-09 0:56
Risa Harada11-May-09 0:56 
I have to use skip list to store ~109000 words from a text file.

Here's the code (I'm using Visual C++ 2008):

Struct of the node:

struct SkipNode
{
	SkipNode ** forward;
	CString mots;
	CString longe;
	CString pos;
};



Make a new node:

SkipNode* make_node(int level, CString mots, CString pos, CString longe) 
{
        SkipNode *sn;
	sn=new SkipNode;
	sn->forward = (SkipNode**)calloc(level + 1, sizeof(SkipNode *));	
        sn->mots = mots;
	sn->pos = pos;
	sn->longe = longe;
	sn->level=level;
    return sn;
}


Insert a node:

void insert(SkipList* ss, CString value, CString pos, CString longe) 
{
    int i;
    SkipNode* x = ss->head;	
    SkipNode* update[MAX_LEVEL + 1];
    memset(update, 0, MAX_LEVEL + 1);
    for(i = ss->level; i >= 0; i--) 
	{
        while(x->forward[i] != NULL && x->forward[i]->mots < value) 
		{
            x = x->forward[i];
        }
        update[i] = x; 
    }
    x = x->forward[0];
    if((x!=NULL)&&(x->mots!=value)||(x==NULL))
	{        
        int lvl = random_level();
        if (lvl > ss->level) 
		{
			for(i = ss->level + 1; i <= lvl; i++) 
			{
				update[i] = ss->head;
			}
		    ss->level = lvl;
		}
        x = make_node(lvl, value, pos, longe);
		for(i = 0; i <= lvl; i++)
		{
			x->forward[i] = update[i]->forward[i];
			update[i]->forward[i] = x;
		}

    }
}


My MAX_LEVEL = 17 (log109000).

I read that skip list takes less time to insert a node than some other data structure (O(log n)). So I wonder why I need ~3 minutes to make the skip list above. And when I stop debugging, the program is still running!? I've just started studying programming, please help me!
AnswerRe: Skip list takes so much time in insertion Pin
Stuart Dootson11-May-09 5:58
professionalStuart Dootson11-May-09 5:58 
GeneralRe: Skip list takes so much time in insertion Pin
Risa Harada11-May-09 6:20
Risa Harada11-May-09 6:20 
Generalproblem with CryptStringToBinary. Pin
Vineet Kumar11-May-09 0:52
Vineet Kumar11-May-09 0:52 
QuestionRe: problem with CryptStringToBinary. Pin
CPallini11-May-09 1:39
mveCPallini11-May-09 1:39 
QuestionEdit Control Problem Pin
Padmanabha_M11-May-09 0:15
Padmanabha_M11-May-09 0:15 

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.