Closed aveldan closed 2 months ago
Thanks once again for the implementation! Can you remove the zeros at the front? I can't understand the need to have these nodes there.Everything else seems pretty good to me.
Do you mean the nodes with value 0
. I think in the example I created I insert 0
as a key value, those 0s
are those values. Or do you mean to remove nodes with root
or NULL
I run this example:
skip_list<int> s(2, 0.3);
s.insert(1);
s.insert(4);
s.insert(13);
s.insert(5);
s.insert(6);
std::cout << s << '\n';
s.visualize();
and the result was this:
But 0 does not exist in the elements
let me check
For me it's still there. No? If im wrong please let me know, i just checked.
This is what I get from example you gave
skip_list<int> s(2, 0.3);
s.insert(1);
s.insert(4);
s.insert(13);
s.insert(5);
s.insert(6);
std::cout << s << '\n';
s.visualize();
I think you might have not updated your code.
The problem I found was that our skip_list's root
had key = 0
in it and I was creating nodes for that and also an extra node called root.
Instead I took care of it by just going to next head = head->next[i]
whenever head
is root
. That should resolve it. I have tried a few other examples also they don't seem to create nodes with 0.
The above one was for this
skip_list<int> s(3, 0.5);
s.insert(3);
s.insert(6);
s.insert(7);
s.insert(9);
s.insert(12);
s.insert(19);
s.insert(17);
s.insert(15);
s.insert(100);
s.insert(500);
s.insert(174);
s.insert(1234);
Yes it is fixed, sorry for this i forgot to fetch your PR and i did not have the updates. PR will be merged
Added visualise for skiplist. #64 This is how it looks for one example