back to scratko.xyz
summaryrefslogtreecommitdiff
path: root/queue.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-04-23 19:03:35 +0300
committerscratko <m@scratko.xyz>2024-05-25 21:12:30 +0300
commitc1e5cffb43977f5a2f8d9623e40c01dab6d80c46 (patch)
tree31c9c9b6847c292b13a354d962b86b6f5e15bb26 /queue.c
downloadshell-I.tar.gz
shell-I.tar.bz2
shell-I.zip
Shell-I releaseshell-I
Diffstat (limited to 'queue.c')
-rw-r--r--queue.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/queue.c b/queue.c
new file mode 100644
index 0000000..861f1e5
--- /dev/null
+++ b/queue.c
@@ -0,0 +1,44 @@
+#include "queue.h"
+#include <stdlib.h>
+
+void queue_init(struct queue *q)
+{
+ q->first = NULL;
+ q->last = NULL;
+}
+
+void queue_push(struct queue *q, char *word)
+{
+ struct word_item *tmp = malloc(sizeof(struct word_item));
+ tmp->word = word;
+ tmp->next = NULL;
+ if(!q->first) {
+ q->first = tmp;
+ q->last = q->first;
+ } else {
+ q->last->next = tmp;
+ q->last = q->last->next;
+ }
+}
+
+void queue_clear(struct queue *q)
+{
+ struct word_item *tmp;
+ while(q->first) {
+ tmp = q->first;
+ q->first = q->first->next;
+ free(tmp->word);
+ free(tmp);
+ }
+ q->last = NULL;
+}
+
+void queue_processing(const struct queue *q, void (*callback)(char*))
+{
+ struct word_item *tmp;
+ tmp = q->first;
+ while(tmp) {
+ callback(tmp->word);
+ tmp = tmp->next;
+ }
+}