diff mbox series

[5/8] queue.3, stailq.3: EXAMPLES: Move stailq example from queue.3 to stailq.3

Message ID 20201024222115.6362-6-colomar.6.4.3@gmail.com
State Not Applicable
Headers show
Series stailq.3 | expand

Commit Message

Alejandro Colomar Oct. 24, 2020, 10:21 p.m. UTC
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/queue.3  | 61 ---------------------------------------------------
 man3/stailq.3 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 61 deletions(-)
diff mbox series

Patch

diff --git a/man3/queue.3 b/man3/queue.3
index ee15e60be..bebfc7a25 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -456,67 +456,6 @@  from the tail queue.
 .Pp
 See the EXAMPLES section below for an example program using a tail queue.
 .Sh EXAMPLES
-.Ss Singly-linked tail queue example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
-    int data;
-    STAILQ_ENTRY(entry) entries;            /* Singly-linked tail queue. */
-};
-
-STAILQ_HEAD(stailhead, entry);
-
-int
-main(void)
-{
-    struct entry    *n1, *n2, *n3, *np;
-    struct stailhead head;                  /* Singly-linked tail queue
-                                               head. */
-
-    STAILQ_INIT(&head);                     /* Initialize the queue. */
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
-    STAILQ_INSERT_HEAD(&head, n1, entries);
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
-    STAILQ_INSERT_TAIL(&head, n1, entries);
-
-    n2 = malloc(sizeof(struct entry));      /* Insert after. */
-    STAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
-    STAILQ_REMOVE(&head, n2, entry, entries);/* Deletion. */
-    free(n2);
-
-    n3 = STAILQ_FIRST(&head);
-    STAILQ_REMOVE_HEAD(&head, entries);     /* Deletion from the head. */
-    free(n3);
-
-    n1 = STAILQ_FIRST(&head);
-    n1->data = 0;
-    for (int i = 1; i < 5; i++) {
-        n1 = malloc(sizeof(struct entry));
-        STAILQ_INSERT_HEAD(&head, n1, entries);
-        n1->data = i;
-    }
-                                            /* Forward traversal. */
-    STAILQ_FOREACH(np, &head, entries)
-        printf("%i\en", np->data);
-                                            /* TailQ Deletion. */
-    n1 = STAILQ_FIRST(&head);
-    while (n1 != NULL) {
-        n2 = STAILQ_NEXT(n1, entries);
-        free(n1);
-        n1 = n2;
-    }
-    STAILQ_INIT(&head);
-
-    exit(EXIT_SUCCESS);
-}
-.Ed
 .Ss Tail queue example
 .Bd -literal
 #include <stddef.h>
diff --git a/man3/stailq.3 b/man3/stailq.3
index 9b0322e68..88cdccbbc 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -255,4 +255,65 @@  using a singly-linked tail queue.
 .SH CONFORMING TO
 .SH BUGS
 .SH EXAMPLES
+.Ss Singly-linked tail queue example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+    int data;
+    STAILQ_ENTRY(entry) entries;            /* Singly-linked tail queue. */
+};
+
+STAILQ_HEAD(stailhead, entry);
+
+int
+main(void)
+{
+    struct entry    *n1, *n2, *n3, *np;
+    struct stailhead head;                  /* Singly-linked tail queue
+                                               head. */
+
+    STAILQ_INIT(&head);                     /* Initialize the queue. */
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
+    STAILQ_INSERT_HEAD(&head, n1, entries);
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
+    STAILQ_INSERT_TAIL(&head, n1, entries);
+
+    n2 = malloc(sizeof(struct entry));      /* Insert after. */
+    STAILQ_INSERT_AFTER(&head, n1, n2, entries);
+
+    STAILQ_REMOVE(&head, n2, entry, entries);/* Deletion. */
+    free(n2);
+
+    n3 = STAILQ_FIRST(&head);
+    STAILQ_REMOVE_HEAD(&head, entries);     /* Deletion from the head. */
+    free(n3);
+
+    n1 = STAILQ_FIRST(&head);
+    n1->data = 0;
+    for (int i = 1; i < 5; i++) {
+        n1 = malloc(sizeof(struct entry));
+        STAILQ_INSERT_HEAD(&head, n1, entries);
+        n1->data = i;
+    }
+                                            /* Forward traversal. */
+    STAILQ_FOREACH(np, &head, entries)
+        printf("%i\en", np->data);
+                                            /* TailQ Deletion. */
+    n1 = STAILQ_FIRST(&head);
+    while (n1 != NULL) {
+        n2 = STAILQ_NEXT(n1, entries);
+        free(n1);
+        n1 = n2;
+    }
+    STAILQ_INIT(&head);
+
+    exit(EXIT_SUCCESS);
+}
+.Ed
 .SH SEE ALSO