CSRT-NTUA / AlgoPlus

AlgoPlus is a C++17 library for complex data structures and algorithms
https://csrt-ntua.github.io/AlgoPlus
Apache License 2.0
159 stars 20 forks source link

Adding visualise for skiplist #65

Closed aveldan closed 2 months ago

aveldan commented 2 months ago

Added visualise for skiplist. #64 This is how it looks for one example unnamed

spirosmaggioros commented 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.

aveldan commented 2 months ago

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

spirosmaggioros commented 2 months ago

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: Στιγμιότυπο οθόνης 2024-07-06, 7 54 14 μμ

But 0 does not exist in the elements

aveldan commented 2 months ago

let me check

spirosmaggioros commented 2 months ago

For me it's still there. No? If im wrong please let me know, i just checked.

aveldan commented 2 months ago

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();

unnamed

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. unnamed1

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);
spirosmaggioros commented 2 months ago

Yes it is fixed, sorry for this i forgot to fetch your PR and i did not have the updates. PR will be merged