Re: [SLUG] Data structures

From: Paul Braman (aeon@tampabay.rr.com)
Date: Tue Nov 12 2002 - 18:10:36 EST


> Hey Everyone,
>
> I've been doing some exploring on the net about data structures. EVERY
> tutorial/explanation/what-have-you tells you what they are, how they
> work, etc., but they do not under any circumstances tell you what you
> would use them for...why would I use a stack, or a linked list, or
> whatever? They also don't say how to use them in {programming language}.
> This has been quite frustrating. Can anyone give me a hint, or point me
> to some documentation that talks about why you'd want to use a given data
> structure?

You can read C++ guides for more detail, but the C++ Standard Library
provides these three data structures: list, deque, and vector.

Basically, a list is like a "linked list". You use one of these when you
may perform manipulation anywhere in the list itself. For instance,
deleting an item out of the center of a linked list is really easy.
Deleting one out of the center of a deque or vector is harder.

A deque is sort of like a stack which you can manipulate at both ends.
You can treat it just like a normal stack by pushing items onto it and
popping them off, or you can treat it like a queue by pushing items on to
the front and popping them off the back. That's where a stack
shines...when you have to manipulate the ends of the data structure.

A vector, or an array, is the kind of data structure you use when you just
need some place to store things. It's very easy to iterate over an array
(unlike deque and list where you have to traverse pointers sometimes)
because everything is contiguous.

There are other data structures out there, like maps and hashes, but these
three basic types will fill most needs pretty well.

Paul Braman
aeon@tampabay.rr.com



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:41:48 EDT