78 lines
2.9 KiB
HTML
78 lines
2.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Queues</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body background="images/back.gif">
|
|
<!--START-->
|
|
|
|
<h3>Queues</h3>
|
|
|
|
A queue is somewhat similar to a stack but it works on a FIFO
|
|
(First-In First-Out) basis. The value that is put in the queue
|
|
first is also the first to be removed from it. It works like
|
|
a queue in a shop. The person who is first in a queue is served
|
|
first. Queues are typically used to store things that still need to be
|
|
done but there are many other uses. The following functions exist (note
|
|
that the first five are equivalent to the functions for stacks; all
|
|
data structures have these five functions):
|
|
|
|
<p>
|
|
<blockquote>
|
|
<tt><b>ds_queue_create()</b></tt>
|
|
Creates a new queue. The function returns an integer as an id that
|
|
must be used in all other functions to access the particular queue.
|
|
You can create multiple queues.<br>
|
|
<tt><b>ds_queue_destroy(id)</b></tt>
|
|
Destroys the queue with the given id, freeing the memory used.
|
|
Don't forget to call this function when you are ready with the structure.<br>
|
|
<tt><b>ds_queue_clear(id)</b></tt>
|
|
Clears the queue with the given id, removing all data from
|
|
it but not destroying it.<br>
|
|
<tt><b>ds_queue_copy(id,source)</b></tt>
|
|
Copies the queue source into the queue with the given id.<br>
|
|
<tt><b>ds_queue_size(id)</b></tt>
|
|
Returns the number of values stored in the queue.<br>
|
|
<tt><b>ds_queue_empty(id)</b></tt>
|
|
Returns whether the queue is empty. This is the same as testing whether the size is 0.<br>
|
|
<tt><b>ds_queue_enqueue(id,val)</b></tt>
|
|
Enters the value in the queue.<br>
|
|
<tt><b>ds_queue_dequeue(id)</b></tt>
|
|
Returns the value that is longest in the queue and removes it from the queue.<br>
|
|
<tt><b>ds_queue_head(id)</b></tt>
|
|
Returns the value at the head of the queue, that is, the value that has
|
|
been the longest in the queue. (It does not remove it from the queue.)<br>
|
|
<tt><b>ds_queue_tail(id)</b></tt>
|
|
Returns the value at the tail of the queue, that is, the value that
|
|
has most recently been added to the queue. (It does not remove it from the queue.)<br>
|
|
<tt><b>ds_queue_write(id)</b></tt>
|
|
Turns the data structure into a string and returns this string. The string can then
|
|
be used to e.g. save it to a file. This provides an easy mechanism for saving data
|
|
structures.<br>
|
|
<tt><b>ds_queue_read(id,str)</b></tt>
|
|
Reads the data structure from the given string (as created by the previous call).<br>
|
|
</blockquote>
|
|
|
|
<!--END-->
|
|
</body>
|
|
</html>
|
|
|
|
<!-- KEYWORDS
|
|
queues
|
|
|
|
ds_queue_create()
|
|
ds_queue_destroy()
|
|
ds_queue_clear()
|
|
ds_queue_copy()
|
|
ds_queue_size()
|
|
ds_queue_empty()
|
|
ds_queue_enqueue()
|
|
ds_queue_dequeue()
|
|
ds_queue_head()
|
|
ds_queue_tail()
|
|
ds_queue_write()
|
|
ds_queue_read()
|
|
|
|
--> |