-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions2.c
58 lines (51 loc) · 840 Bytes
/
functions2.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
#include "monty.h"
/**
* f_pall - print everything in stack
* @head: pointer to pointer of first node
* @counter: line counter (not used)
*
* Return: none
*/
void f_pall(stack_t **head, unsigned int counter)
{
stack_t *h;
(void)counter;
h = *head;
if (h == NULL)
return;
while (h)
{
printf("%d\n", h->n);
h = h->next;
}
}
/**
* f_swap - swap first two elements of stack
* @head: first node
* @counter: line counter
*
* Return: none
*/
void f_swap(stack_t **head, unsigned int counter)
{
stack_t *h;
int length = 0, temp;
h = *head;
while (h)
{
h = h->next;
length++;
}
if (length < 2)
{
fprintf(stderr, "L%d: can't swap, stack too short\n", counter);
fclose(bus.file);
free(bus.content);
free_stack(*head);
exit(EXIT_FAILURE);
}
h = *head;
temp = h->n;
h->n = h->next->n;
h->next->n = temp;
}