diff mbox series

[v2,05/10] list.3, queue.3: EXAMPLES: Move example program from queue.3 to list.3

Message ID 20201020213107.83837-6-colomar.6.4.3@gmail.com
State Not Applicable
Headers show
Series list.3: New page forked from queue.3 | expand

Commit Message

Alejandro Colomar Oct. 20, 2020, 9:31 p.m. UTC
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/list.3  | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 man3/queue.3 | 53 ----------------------------------------------------
 2 files changed, 53 insertions(+), 53 deletions(-)
diff mbox series

Patch

diff --git a/man3/list.3 b/man3/list.3
index 1a197fe31..6252aaf6a 100644
--- a/man3/list.3
+++ b/man3/list.3
@@ -221,4 +221,57 @@  See the EXAMPLES section below for an example program using a linked list.
 .SH CONFORMING TO
 .SH BUGS
 .SH EXAMPLES
+.Ss List example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+    int data;
+    LIST_ENTRY(entry) entries;              /* List. */
+};
+
+LIST_HEAD(listhead, entry);
+
+int
+main(void)
+{
+    struct entry    *n1, *n2, *n3, *np;
+    struct listhead head;                   /* List head. */
+    int     i;
+
+    LIST_INIT(&head);                       /* Initialize the list. */
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
+    LIST_INSERT_HEAD(&head, n1, entries);
+
+    n2 = malloc(sizeof(struct entry));      /* Insert after. */
+    LIST_INSERT_AFTER(n1, n2, entries);
+
+    n3 = malloc(sizeof(struct entry));      /* Insert before. */
+    LIST_INSERT_BEFORE(n2, n3, entries);
+
+    i = 0;                                  /* Forward traversal. */
+    LIST_FOREACH(np, &head, entries)
+        np->data = i++;
+
+    LIST_REMOVE(n2, entries);               /* Deletion. */
+    free(n2);
+                                            /* Forward traversal. */
+    LIST_FOREACH(np, &head, entries)
+        printf("%i\en", np->data);
+                                            /* List Deletion. */
+    n1 = LIST_FIRST(&head);
+    while (n1 != NULL) {
+        n2 = LIST_NEXT(n1, entries);
+        free(n1);
+        n1 = n2;
+    }
+    LIST_INIT(&head);
+
+    exit(EXIT_SUCCESS);
+}
+.Ed
 .SH SEE ALSO
diff --git a/man3/queue.3 b/man3/queue.3
index 6ee793e25..0f55a899e 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -1155,59 +1155,6 @@  main(void)
     exit(EXIT_SUCCESS);
 }
 .Ed
-.Ss List example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
-    int data;
-    LIST_ENTRY(entry) entries;              /* List. */
-};
-
-LIST_HEAD(listhead, entry);
-
-int
-main(void)
-{
-    struct entry    *n1, *n2, *n3, *np;
-    struct listhead head;                   /* List head. */
-    int     i;
-
-    LIST_INIT(&head);                       /* Initialize the list. */
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
-    LIST_INSERT_HEAD(&head, n1, entries);
-
-    n2 = malloc(sizeof(struct entry));      /* Insert after. */
-    LIST_INSERT_AFTER(n1, n2, entries);
-
-    n3 = malloc(sizeof(struct entry));      /* Insert before. */
-    LIST_INSERT_BEFORE(n2, n3, entries);
-
-    i = 0;                                  /* Forward traversal. */
-    LIST_FOREACH(np, &head, entries)
-        np->data = i++;
-
-    LIST_REMOVE(n2, entries);               /* Deletion. */
-    free(n2);
-                                            /* Forward traversal. */
-    LIST_FOREACH(np, &head, entries)
-        printf("%i\en", np->data);
-                                            /* List Deletion. */
-    n1 = LIST_FIRST(&head);
-    while (n1 != NULL) {
-        n2 = LIST_NEXT(n1, entries);
-        free(n1);
-        n1 = n2;
-    }
-    LIST_INIT(&head);
-
-    exit(EXIT_SUCCESS);
-}
-.Ed
 .Ss Tail queue example
 .Bd -literal
 #include <stddef.h>