Product SiteDocumentation Site

5.3.12.17. insert


>>-insert(item-+--------+-)------------------------------------><
               +-,index-+

Returns a queue-supplied index for item, which is added to the queue. The inserted item follows any existing item with index index in the queue ordering. If index is the Nil object, item is inserted at the head of the queue. If you omit index, item becomes the last item in the queue.
Inserting an item in the queue at position index will cause the items in the queue after position index to have their indexes modified by the queue object.

Example 5.170. Queue class - insert method

musketeers=.queue~of("Porthos","Athos","Aramis) /* Creates queue MUSKETEERS       */
                                                /* consisting of: Porthos         */
                                                /*                Athos           */
                                                /*                Aramis          */
index=musketeers~first                     /* Gives index of first item      */
musketeers~insert("D'Artagnan",index) /* Adds D'Artagnan after Porthos  */
                                           /* List is now: Porthos           */
                                           /*              D'Artagnan   */
                                           /*              Athos             */
                                           /*              Aramis            */
/* Alternately, you could use */
musketeers~insert("D'Artagnan",.nil)  /* Adds D'Artagnan before Porthos */
                                           /* List is now:  D'Artagnan  */
                                           /*               Porthos          */
                                           /*               Athos            */
                                           /*               Aramis           */
/* Alternately, you could use */
musketeers~insert("D'Artagnan")       /* Adds D'Artagnan after Aramis   */
                                           /* List is now:  Porthos          */
                                           /*               Athos            */
                                           /*               Aramis           */
                                           /*               D'Artagnan  */