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(-)
@@ -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
@@ -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>