Arrays, Lists, Queues, and Stacks (at the water park)

Arrays, Lists, Queues, and Stacks (at the water park)

Time for a little more fun with early programming concepts. Most modern programming languages such as Java and C# have collections, groups of values of the same type collected together in different ways. It can be a little hard to visualize how the different types of collections work. So, let's go to the water park to explore.


Parking lot with single row of colorful cars.

The Array is like a narrow parking lot outside the water park with a single row of parking spaces. You can only have as many cars as you have parking spots. Any specific car, such as the third, can drive away. but the parking space is still there and only one new car can drive into that open spot. Anybody else has to wait or visit a different water park.


Channel with rubber boats and a speech bubble, "Go to the end, or the middle. Whatever, man."?

The List is like a row of rubber rafts bobbing on the water in a narrow channel inside the water park. The channel starts out empty, and every new rubber raft with riders goes to the end. Except, sometimes somebody is pushy and wants to be the third raft, so they go to that spot and shove the other rafts a bit to make room for the new raft. The riders of the other rafts may grumble, but they move back or forward to make room. Likewise, somebody may want to grab their raft from somewhere in the middle of the channel and go home because Suzie feels so nauseated from the motion of the water, so they just pull the raft out, in which case all the other rafts squidge forward and back to make a single row again.


No alt text provided for this image

The Queue is like the List but it is watched over by Gerald the Grumpy Guard who has an oversized sense of his own power. Gerald will only let the rafts enter at one end of the channel and exit out the other end, so the first one in is the first one out and that's it, quit your whining!


No alt text provided for this image

The Stack is like the Queue except Vanessa the Vicious Vandal blocked off one end of the channel with large wet mattresses coated in cement, and Gerald the Grumpy Guard still won't let anybody come or go from the middle, so the last one in is the only one who can get out again, even if they gripe that they just got there and it is no fair!

I hope that helps you visualize these four Collections a little better. But even if it doesn't, now you'll have an excuse to go to the water park to "study" and ponder the peculiarities of programming concepts while you float on your rubber raft.

要查看或添加评论,请登录

Ben Langhinrichs的更多文章

  • All the web's a stage! (Full Stack version)

    All the web's a stage! (Full Stack version)

    If you've ever been at a social event and heard someone use the term full stack web development, you may have veered…

  • Loops, Camels, and Coconuts

    Loops, Camels, and Coconuts

    One of the most important early concepts to learn in programming is the idea of loops. While a statement does one thing…

  • Exception Handling (Babysitter edition)

    Exception Handling (Babysitter edition)

    Time for another fun article on programming concepts, this time on exception handling. Or, as I like to say, "When you…

  • Arrays and other Collections (at the water park)

    Arrays and other Collections (at the water park)

    Time for more fun with early programming concepts. This is an update of an earlier article, now with more Collections!…

    3 条评论
  • A Party Inside the RESTful Academy

    A Party Inside the RESTful Academy

    Behind almost every web page there are services, and these web services are more often than not built with REST APIs…

  • Inheritance & Polymorphism (& smelly butts)

    Inheritance & Polymorphism (& smelly butts)

    I'm trying with these articles to provide simplified, visual representations of basic programming concepts. Inheritance…

  • If, Else, Else If, and nested If

    If, Else, Else If, and nested If

    When learning programming for the very first time, there are certain concepts that can be hard to wrap your head…

  • CoexLinks Fidelity: Give 1998 its email back

    CoexLinks Fidelity: Give 1998 its email back

    If you would be interested in a short, 15 minute online demo, I'd be happy to show you how IBM Notes/Domino email…

社区洞察

其他会员也浏览了