-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c4d5913
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |