Home Segments Index Top Previous Next

411: Mainline

Using the addLast:, first, and removeFirst methods, you can use ordered collections to represent first-in, first-out (FIFO) queues:

   *-- first reads elements from the front 
   | 
   *-- removeFirst removes elements from the front 
   | 
   v              
 *---*---*---*---*---* 
 |   |   |   |   |   | 
 *---*---*---*---*---* 
                      ^ 
                      *-- addLast: adds elements at the back 

Similarly, you can use ordered collections to represent last-in, first-out (LIFO) push-down stacks by using the addFirst:, first, and removeFirst methods:

   *-- first reads elements from the front 
   | 
   *-- removeFirst removes elements from the front 
   | 
   v              
 *---*---*---*---*---* 
 |   |   |   |   |   | 
 *---*---*---*---*---* 
^ 
*-- addFirst: adds elements to the front