Skip to content

Functions

Akshay Mohan edited this page Jan 13, 2019 · 3 revisions

Insertion

Below are the functions that are used to perform enqueue operation in a queue. Both linear and circular queue share the same functions for insertion and deletion except for queue_force_enqueue.

queue_enqueue

  • Description:

    • Inserts given element to the queue.
  • Parameters:

    • Queue[] - Queue on which value is to be inserted.
    • value - Value to be inserted.
  • Return value:

    • -1 - On failure | Full in case of circular queue; Rear position won't go any further in case of a linear queue.
    • The rear-most position of the queue (ie; values >= 0).
  • Alias:

    • queue_insert
    • queue_add
  • Example:

new Queue:test<10>;
queue_enqueue(test, 1);
queue_insert(test, 3);
queue_add(test, 10);



queue_force_enqueue

  • Description:

    • Forcefully inserts given element to the queue. Function overwrites existing element if the queue is full.
    • This function can be used only for circular queues.
  • Parameters:

    • Queue[] - Circular queue on which value has to be inserted forcefully.
    • value - Value to be inserted.
  • Return value:

    • The rear-most position of the queue.
  • Alias:

    • queue_force_insert
    • queue_force_add
  • Example:

new QueueC:newsQueue<MAX_MESSAGES>;
queue_force_enqueue(newsQueue, news_id);





Deletion

work-in-progress

Clone this wiki locally