4

I hate data structures. I try to work out their algorithms in my head but they're completely counterintuitive. lol.

Comments
  • 1
    try drawing them, it helps
  • 1
    Everything is just a multi-dimensional array in my head. Sometimes associative, sometimes numerically indexed, but always that same multi-dimensional array.

    After that it's just syntax.
  • 0
    @Midnight-shcode Still having issues but yeah it helps.
  • 1
    Anything specific?
  • 1
    @IntrusionCM I'm trying to implement a Stack in Java using classic arrays. Don't worry though, I'm trying to get there on my own.

    In the beginning it worked when I expanded the array by creating a new one and switching references, but now it doesn't work anymore when I don't use that system. Right now I'm having issues with using indexes to keep shifting pushed values around. A stack should be: D C B A, not A B C D. Currently have B A A. It's a bug, so yeah, figuring that out. lol.
  • 1
    @IntrusionCM Okay I solved it.

    Problem 1:
    For each item on the stack, assign it to item+1 index and then assign index 0 to the newly added item.
    This copies item0 to item1 and item1 to item2, but then leaves a bug where item1 and item2 are now the same because item0 didn't change index yet.

    Problem 2:
    You iterate through the array, but when you reach the end of the array, you get a boundary error because you're trying to assign the item in the next slot, which doesn't exist.

    Solution:
    Iterate negatively in reverse: keep reassigning indexes in reverse until there are no more items to process. Avoids boundary error.
  • 0
    @CaptainRant ah.

    I like to play with my text markers for stuff like that.

    As each text marker has it's own color it's easier to visualize.

    Especially when some dumbtard decided nesting ifs 5 level deep and I need to decipher which if does what.

    Yellow text marker - first indent
    Post it on the text marker with the branching (True - does X, False - does Y)
    Green text marker - second indent
    Post it on it with the branching....
    And so on.

    It's a lifesaver for these things and more fun / joyful than e.g. drawing UML -/ VK -/ ... diagrams.

    (I just lay down the text markers as building blocks, I don't draw with them... But for algorithms or refactoring it's nice to be able to move stuff around without writing tons of stuff to see the outcome. 🤣)
  • 0
    dk bout DSA but I learnt this new word
    "counterintuitive"

    P.S : English is my 3rd speaking language
Add Comment