Solved

basic types

Posted on 1999-01-25
10
180 Views
Last Modified: 2010-04-02
could someone please explain to me the differences between the types
vector, list, map, multimap, queue, priority queue, stack, and deque?
this is not for homework, but I am trying to figure out some basic c++ for myself.

thanks
0
Comment
Question by:alfino
  • 5
  • 4
10 Comments
 
LVL 8

Accepted Solution

by:
MaDdUCK earned 720 total points
ID: 1185087
answer pending...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185088
MaDdUCK - an interesting answer... Hunting points?
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1185089
alfino,
this is not easy to answer for all the types you addressed are basically arrays (except for multimap) that are optimized for different purposes and actions. Such actions include subscripting, adding, deleting, pushing and popping, sorting, etc. I will run through your list and try my best:

vector: the easiest, comparable to an [] arry of C but with range checking. Optimized for subscripting (vector::at() and vector::operator[]()).

list: like a vector, but optimized for addition, insertion, and deletion. Subscripting is painfully slow and not provided. Lists are easy to sort, split, and merge though.

stack: imagine a stack of papers. the principle "first in last out" applies here. The paper that you put down first (the one at the bottom) is taken out last. Stacks are used for hierarchies and are optimized for pushing and popping (adding and deleting the upper-most element). Sorting and other order-changing operations are not supported, and subscripting and insertions make no sense.

queue: like a supermarket queue: first in first out. The person first in the line (queue) will be first out. Pushing (adding to one end) and popping (removing from the oother) are provided.

deque: like a queue except that popping and pushing can occur on both sides of the queue.

priority queue: like a queue, except that each member can have a priority. this is comparable to a print queue where some documents, although submitted later have to be printed before others.

map and multimap: these are hashes, meaning that they associate pairs like a two-column table. Sometimes they are referred to as dictionaries. They are optimized for search, addition and deletion, and are automatically sorted. A multimap can have multiple entries for one key, a map can only have one value for one specific key.

so I hope this helps and I did not leave anything out.
\\MaD dUCK
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1185090
I just want to be sure that if I spend all the time and effort to answer it that noone else will have proposed an answer before I can. I don't think that the method used was inappropriate or against the rules.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185091
alfino - the best descriptions for this are available in Bjarne Stoustroup's book on C++, 'The C++ Programming language', Addison-Wesley. I have to admit that i thought of copying and pasting the descriptions from my online documentation, but that'd be a strange way to earn points ;-)
BTW - That's what most of the explanations you'll get here will contain:

vector: describes an object that controls a varying-length sequence of elements. The sequence is stored as an array.

list: describes an object that controls a varying-length sequence of elements. The sequence is stored as a bidirectional linked list of elements.

map: describes an object that controls a varying-length sequence of elements. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations proportional to the logarithm of the number of elements in the sequence (logarithmic time). Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators that point at the removed element.


0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Expert Comment

by:jkr
ID: 1185092
>>I don't think that the method used was inappropriate or
>>against the rules.
I don't either - but it's unusual, anyway ;-)
PS: Gruß aus Schwaben ;-)

0
 

Author Comment

by:alfino
ID: 1185093
thanks both of you. i got what i wanted (a description and a reference) from both of you so I am happy.
jkr: do you want points too? if so, I could ask Linda to split...
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1185094
und von wo aus dem Schwabenländle? Bin zwar gerade in Amerika-land, aber dennoch eigentlich in Bayern zu Hause...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185095
Tja, Heilbronn hier, bin aber ein Bayer in der Diaspora ;-)
Da das ja eine (recht teure) PAQ ist, kann ich ja 'mal sorglos meine email posten (mach' ich sonst nich' ;-) - erreichbar unter
** email address removed by Netminder, EE Admin **
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185096
>>jkr: do you want points too? if so, I could ask Linda to
>>split...
If you think i earned some ;-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now