-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeq_a_loc.c
112 lines (104 loc) · 2.64 KB
/
deq_a_loc.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
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* deq_a_loc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanglee2 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/28 20:19:28 by sanglee2 #+# #+# */
/* Updated: 2023/05/30 22:32:22 by sanglee2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <limits.h>
static int get_a_loc_bigger(t_deq* deq_a, t_node* temp)
{
int deq_a_loc;
int cur_loc;
int min_a;
cur_loc = 0;
min_a = INT_MAX;
temp = deq_a->a_top;
while(temp)
{
if (temp->index < min_a)
{
min_a = temp->index;
deq_a_loc = cur_loc;
}
temp = temp->next;
cur_loc++;
}
return (deq_a_loc);
}
int get_a_loc(t_deq* deq_a, int b_content)
{
int deq_a_loc;
int cur_loc;
int min;
t_node* temp;
cur_loc = 0;
min = INT_MAX;
temp = deq_a->a_top;
while (temp)
{
if (b_content < temp->index && min > temp->index - b_content)
{
min = temp->index - b_content;
deq_a_loc = cur_loc;
}
temp = temp->next;
cur_loc++;
}
if (min == INT_MAX)
deq_a_loc = get_a_loc_bigger(deq_a, temp);
//deq_a->a_size = get_deq_a_size(deq_a);
if (deq_a_loc > deq_a->a_size / 2)
deq_a_loc = (deq_a->a_size - deq_a_loc) * -1;
return (deq_a_loc);
}
// int get_a_loc(t_deq* deq_a, int b_content)
// {
// int deq_a_loc;
// int cur_loc;
// int min;
// int min_a;
// t_node* temp;
// deq_a_loc = 0;
// cur_loc = 0;
// min = INT_MAX;
// min_a = INT_MAX;
// temp = deq_a->a_top;
// while (temp)
// {
// if (b_content < temp->index)
// {
// if (min > temp->index - b_content)
// {
// min = temp->index - b_content;
// deq_a_loc = cur_loc;
// }
// }
// temp = temp->next;
// cur_loc++;
// }
// if (min == INT_MAX)
// {
// temp = deq_a->a_top;
// cur_loc = 0;
// while(temp)
// {
// if (temp->index < min_a)
// {
// min_a = temp->index;
// deq_a_loc = cur_loc;
// }
// temp = temp->next;
// cur_loc++;
// }
// }
// deq_a->a_size = get_deq_a_size(deq_a);
// if (deq_a_loc > deq_a->a_size / 2)
// deq_a_loc = (deq_a->a_size - deq_a_loc) * -1;
// return (deq_a_loc);
// }