Skip to content

Commit

Permalink
feat: rotr
Browse files Browse the repository at this point in the history
  • Loading branch information
horpeazy committed Oct 7, 2022
1 parent 1581c96 commit fe4571b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bytecodes/35.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
push 9
push 0
pall
rotl
rotr
pall
1 change: 1 addition & 0 deletions get_operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void (*get_op(char *name))(stack_t **, unsigned int)
{"pchar", pchar},
{"pstr", pstr},
{"rotl", rotl},
{"rotr", rotr},
{NULL, NULL}
};

Expand Down
Binary file modified monty
Binary file not shown.
1 change: 1 addition & 0 deletions monty.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void _mod(stack_t **stack, unsigned int line_number);
void pchar(stack_t **stack, unsigned int line_number);
void pstr(stack_t **stack, unsigned int line_number);
void rotl(stack_t **stack, unsigned int line_number);
void rotr(stack_t **stack, unsigned int line_number);

/* Miscellaneous */
void (*get_op(char *name))(stack_t **stack, unsigned int line_number);
Expand Down
23 changes: 23 additions & 0 deletions rotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,26 @@ void rotl(stack_t **stack, unsigned int line_number)
node->prev = temp;
node->next = NULL;
}

/**
* rotr - rotates the stack
* @stack: pointer to stack
* @line_number: line number of opcode
*/
void rotr(stack_t **stack, unsigned int line_number)
{
stack_t *temp;

if (!stack || !*stack || !(*stack)->next)
return;

(void) line_number;
temp = *stack;

while (temp->next)
temp = temp->next;
temp->prev->next = NULL;
temp->next = *stack;
temp->prev = NULL;
*stack = temp;
}

0 comments on commit fe4571b

Please sign in to comment.