Click here to Skip to main content
16,004,974 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Halting execution until a button is clicked Pin
Simon Cornish8-Dec-05 21:21
Simon Cornish8-Dec-05 21:21 
Questionlinking assembly dll to project Pin
9ine7-Dec-05 3:46
9ine7-Dec-05 3:46 
AnswerRe: linking assembly dll to project Pin
Nish Nishant7-Dec-05 4:03
sitebuilderNish Nishant7-Dec-05 4:03 
GeneralRe: linking assembly dll to project Pin
9ine7-Dec-05 5:24
9ine7-Dec-05 5:24 
GeneralRe: linking assembly dll to project Pin
Nish Nishant7-Dec-05 7:12
sitebuilderNish Nishant7-Dec-05 7:12 
GeneralRe: linking assembly dll to project Pin
Saksida Bojan7-Dec-05 19:56
Saksida Bojan7-Dec-05 19:56 
GeneralRe: linking assembly dll to project Pin
9ine7-Dec-05 22:09
9ine7-Dec-05 22:09 
QuestionHelp please with Skip List Pin
Reunion7-Dec-05 2:00
Reunion7-Dec-05 2:00 
Hello!

I need to make a skip list in my application and I decided to take code from Robert Sedgewick's book "Algorithms in C++", but faced one serious problem: the insert function sometimes failes. I don't know why. Here is it:

const int lgNmax = 10;
template <class Item, class Key>
class SkipList
{
private:
    struct node{
        Item item;
        node **next;
        int sz;
        node(Item x, int k)
        {
            item = x;
            sz = k;
            next = new node*[k];
            for(int i = 0; i < k; i++)
                next[i] = 0;
        }
    };

    typedef node *link;
    link head;
    Item nullItem;
    int lgN;

    ...

    int _randX()
    {
        int i, j, t = rand();

        for(i = 1, j = 2; i < lgNmax; i++, j += j)
            if(t > RAND_MAX / j)
                break;
        if(i > lgN)
            lgN = i;

        return i;
    }

    void _insert(link t, link x, int k)
    {
        Key v = x->item.Key();
        link tk = t->next[k];

        if(!tk || v < tk->item.Key()){    // here
            if(k < x->sz){
                x->next[k] = tk;
                t->next[k] = x;
            }
            if(k == 0)
                return;
            _insert(t, x, k - 1);
            return;
        }
        _insert(tk, x, k);
    }

public:
    SkipList()
    {
        head = new node(nullItem, lgNmax);
        lgN = 0;
        srand((unsigned int)time(NULL));
    }

    void Insert(Item v)
    {
        _insert(head, new node(v, _randX(), lgN);
    }

    ...
};


And the problem is with the 'if(!tk || v < tk->item.Key()){' line (marked with comment). The problem is that the tk sometimes becomes 0xfdfdfdfd. I can't understand why and how to avoid this. It happens at the first iteration of _insert() when t = head. And this usually happens at 300th - 600th insertion. Could you help me to remove the bug?

Thank you in advance!
AnswerRe: Help please with Skip List Pin
Nish Nishant7-Dec-05 4:02
sitebuilderNish Nishant7-Dec-05 4:02 
AnswerRe: Help please with Skip List Pin
Blake Miller7-Dec-05 9:33
Blake Miller7-Dec-05 9:33 
GeneralRe: Help please with Skip List Pin
Reunion7-Dec-05 19:47
Reunion7-Dec-05 19:47 
Questionwho can help me design this project Pin
chen10006-Dec-05 15:22
chen10006-Dec-05 15:22 
AnswerRe: who can help me design this project Pin
chen10006-Dec-05 15:29
chen10006-Dec-05 15:29 
AnswerRe: who can help me design this project Pin
toxcct6-Dec-05 21:45
toxcct6-Dec-05 21:45 
JokeRe: who can help me design this project Pin
Nish Nishant7-Dec-05 0:12
sitebuilderNish Nishant7-Dec-05 0:12 
Question&quot;EXPORTING STATIC AND NON-MEMBER FUNCTIONS Pin
barry1234-Dec-05 20:42
barry1234-Dec-05 20:42 
AnswerRe: &amp;quot;EXPORTING STATIC AND NON-MEMBER FUNCTIONS Pin
barry1238-Dec-05 21:38
barry1238-Dec-05 21:38 
QuestionISAPI Extension Pin
jain304-Dec-05 18:50
jain304-Dec-05 18:50 
QuestionConversion Pin
need4change4-Dec-05 2:18
need4change4-Dec-05 2:18 
AnswerRe: Conversion Pin
S. Senthil Kumar4-Dec-05 2:45
S. Senthil Kumar4-Dec-05 2:45 
AnswerRe: Conversion Pin
Saksida Bojan4-Dec-05 19:39
Saksida Bojan4-Dec-05 19:39 
AnswerRe: Conversion Pin
toxcct5-Dec-05 0:53
toxcct5-Dec-05 0:53 
QuestionVruses? Pin
Lord Kixdemp2-Dec-05 20:33
Lord Kixdemp2-Dec-05 20:33 
AnswerRe: Vruses? Pin
Christian Graus7-Dec-05 15:01
protectorChristian Graus7-Dec-05 15:01 
GeneralRe: Vruses? Pin
Lord Kixdemp9-Dec-05 12:29
Lord Kixdemp9-Dec-05 12:29 

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.