-
Notifications
You must be signed in to change notification settings - Fork 3
/
choose_option_4.c
107 lines (99 loc) · 1.95 KB
/
choose_option_4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "monty.h"
/**
* m_pstr - prints the string starting at the top of the stack + '\n'
* @stack: address of doubly linked list
* @line_number: line number
*/
void m_pstr(stack_t **stack, unsigned int line_number)
{
stack_t *tmp = *stack;
char str[1028];
size_t i = 0;
(void)line_number;
if (!tmp)
{
printf("\n");
return;
}
for (; tmp->next; tmp = tmp->next)
;
for (; tmp && tmp->n; tmp = tmp->prev, i++)
{
if (tmp->n <= 0 || tmp->n > 126)
break;
str[i] = tmp->n;
}
str[i] = '\0';
printf("%s\n", str);
}
/**
* isint - checks if s could be converted to an decimal int
* @s: sourcer string
* Return: 0 on success, otherwise 1
*/
int isint(char *s)
{
size_t i;
if (!s)
return (1);
for (i = 0; s[i]; i++)
{
if ((s[i] < 48 || s[i] > 57) && (s[i] != '-'))
return (1);
}
return (0);
}
/**
* m_rotl - rotates the stack to the top
* @stack: address of doubly linked list
* @line_number: line number
*/
void m_rotl(stack_t **stack, unsigned int line_number)
{
stack_t *tmp = *stack;
(void)line_number;
if (!(*stack) || !((*stack)->next))
return;
for (; tmp->next; tmp = tmp->next)
;
tmp->prev->next = NULL;
tmp->prev = NULL;
tmp->next = *stack;
(*stack)->prev = tmp;
*stack = tmp;
}
/**
* m_rotr - rotates the stack to the bottom
* @stack: address of doubly linked list
* @line_number: line number
*/
void m_rotr(stack_t **stack, unsigned int line_number)
{
stack_t *tmp = *stack;
(void)line_number;
if (!(*stack) || !((*stack)->next))
return;
for (; tmp->next; tmp = tmp->next)
;
tmp->next = *stack;
(*stack)->prev = tmp;
(*stack)->next->prev = NULL;
*stack = (*stack)->next;
tmp->next->next = NULL;
}
/**
* m_queue - changes structure to queue mode
* @stack: address of doubly linked list
* @line_number: line number
*/
void m_queue(stack_t **stack, unsigned int line_number)
{
cmds *tmp = head;
(void)stack;
(void)line_number;
if (!tmp->mode)
{
for (; tmp; tmp = tmp->next)
tmp->mode = 1;
}
}