From c4d5913b8e0d67b13e57b3a30bf9a334680c3758 Mon Sep 17 00:00:00 2001 From: jekwupeter Date: Thu, 16 Jun 2022 16:42:55 +0100 Subject: [PATCH] task upload --- README.md | 1 + dlinked_list_functions.c | 29 +++++++++++++++++++++++++++++ monty.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 README.md create mode 100644 dlinked_list_functions.c create mode 100644 monty.h diff --git a/README.md b/README.md new file mode 100644 index 0000000..345e6ae --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Test diff --git a/dlinked_list_functions.c b/dlinked_list_functions.c new file mode 100644 index 0000000..08ebf71 --- /dev/null +++ b/dlinked_list_functions.c @@ -0,0 +1,29 @@ +#include "monty.h" +/** + * add_dnodeint - adds a new node to beggining of dlinked list + * @stack_ptr: pointer to top of dlinked list + * @n: input data for new node + * + * Return: adress to new dnode added + * + * */ +stack_t *add_dnodeint(stack_t **stack_ptr, const int n) +{ + stack_t *new_node; + + /* allocate memory to node */ + new_node = (stack_t *)malloc(sizeof(stack_t)); + if (new_node == NULL) + return (NULL); + + new_node->n = n;/* put in data*/ + /* make next of new node as head & prev as NULL */ + new_node->next = n; + new_node->prev = NULL; + + /* change the prev of head node to new node */ + if ((*stack_ptr) != NULL) + (*stack_ptr)->prev = new_node + + return (newnode); +} diff --git a/monty.h b/monty.h new file mode 100644 index 0000000..6649fc1 --- /dev/null +++ b/monty.h @@ -0,0 +1,32 @@ +#ifndef MONTY_H +#define MONTY_H +/** + * struct stack_s - doubly linked list representation of a stack (or queue) + * @n: integer + * @prev: points to the previous element of the stack (or queue) + * @next: points to the next element of the stack (or queue) + * + * Description: doubly linked list node structure + * for stack, queues, LIFO, FIFO + */ +typedef struct stack_s +{ + int n; + struct stack_s *prev; + struct stack_s *next; +} stack_t; +/** + * struct instruction_s - opcode and its function + * @opcode: the opcode + * @f: function to handle the opcode + * + * Description: opcode and its function + * for stack, queues, LIFO, FIFO + */ +typedef struct instruction_s +{ + char *opcode; + void (*f)(stack_t **stack, unsigned int line_number); +} instruction_t; +extern stack_t *stack_ptr = NULL; +#endif