If you look at the Container ADT (abstract data type) as a black box, it provides two functions:
1. put(C, x)
2. get(C)
The first function will put the object x into container C. The second will retrieve the "next" object from container C, where "next" depends on what type of container you want. A stack implementation would return the element that was most recently put into the container (also known as a FILO ADT).
My question is, in it's most generic form, does the Container ADT function get() remove the element itself from the container, or does it simply return a reference to it for access, retaining the element in the Container?
if you have only put()
and get()
, get()
must also remove the element, otherwise you won't have access to the nth element for each n!=1.
the idea is with enough get()
oporations, you should be able to access each element in the container, and if get()
doesn't remove the element, sequential get()
's will always return the same element, so only the first element is accessable.
but it can be different for each implementation, of course. (for example, you can create a ADT with put(), get() and pop(), where get will only return the element.