diff options
Diffstat (limited to 'dis/Pointer/pointer.c')
-rw-r--r-- | dis/Pointer/pointer.c | 121 |
1 files changed, 60 insertions, 61 deletions
diff --git a/dis/Pointer/pointer.c b/dis/Pointer/pointer.c index 3f3eefb..d97f276 100644 --- a/dis/Pointer/pointer.c +++ b/dis/Pointer/pointer.c | |||
@@ -82,68 +82,67 @@ int main(int argc, char **argv) { | |||
82 | return (-1); | 82 | return (-1); |
83 | 83 | ||
84 | randInit(seed); | 84 | randInit(seed); |
85 | for (l = 0; l < f; l++) { | 85 | for_each_job { |
86 | field[l] = randInt(0, f - w); | 86 | for (l = 0; l < f; l++) { |
87 | } | 87 | field[l] = randInt(0, f - w); |
88 | startTime = time(NULL); | 88 | } |
89 | clock(); | 89 | startTime = time(NULL); |
90 | 90 | ||
91 | START_LOOP | 91 | for (l = 0; l < n; l++) { |
92 | for (l = 0; l < n; l++) { | 92 | unsigned int index; |
93 | unsigned int index; | 93 | unsigned int minStop, maxStop; |
94 | unsigned int minStop, maxStop; | 94 | unsigned int hops; |
95 | unsigned int hops; | 95 | |
96 | 96 | hops = 0; | |
97 | hops = 0; | 97 | minStop = thread[l].minStop; |
98 | minStop = thread[l].minStop; | 98 | maxStop = thread[l].maxStop; |
99 | maxStop = thread[l].maxStop; | 99 | index = thread[l].initial; |
100 | index = thread[l].initial; | 100 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { |
101 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { | 101 | |
102 | 102 | unsigned int ll, lll; | |
103 | unsigned int ll, lll; | 103 | unsigned int max, min; |
104 | unsigned int max, min; | 104 | unsigned int partition; |
105 | unsigned int partition; | 105 | unsigned int high; |
106 | unsigned int high; | 106 | |
107 | 107 | partition = field[index]; | |
108 | partition = field[index]; | 108 | max = MAX_FIELD_SIZE; |
109 | max = MAX_FIELD_SIZE; | 109 | min = 0; |
110 | min = 0; | 110 | high = 0; |
111 | high = 0; | 111 | |
112 | 112 | for (ll = 0; ll < w; ll++) { | |
113 | for (ll = 0; ll < w; ll++) { | 113 | unsigned int balance; |
114 | unsigned int balance; | 114 | unsigned int x; |
115 | unsigned int x; | 115 | x = field[index + ll]; |
116 | x = field[index + ll]; | 116 | |
117 | 117 | if (x > max) | |
118 | if (x > max) | ||
119 | high++; | ||
120 | else if (x > min) { /* start else* */ | ||
121 | partition = x; | ||
122 | balance = 0; | ||
123 | for (lll = ll + 1; lll < w; lll++) { | ||
124 | if (field[index + lll] > partition) | ||
125 | balance++; | ||
126 | } /* end for loop */ | ||
127 | |||
128 | if (balance + high == w / 2) | ||
129 | break; | ||
130 | else if (balance + high > w / 2) { | ||
131 | min = partition; | ||
132 | } /* end if */ | ||
133 | else { | ||
134 | max = partition; | ||
135 | high++; | 118 | high++; |
136 | } /* end else */ | 119 | else if (x > min) { /* start else* */ |
137 | } | 120 | partition = x; |
138 | if (min == max) | 121 | balance = 0; |
139 | break; | 122 | for (lll = ll + 1; lll < w; lll++) { |
140 | } /* end else* */ | 123 | if (field[index + lll] > partition) |
141 | index = (partition + hops) % (f - w); | 124 | balance++; |
142 | hops++; | 125 | } /* end for loop */ |
143 | } /* end loop ll */ | 126 | |
144 | thread[l].hops = hops; | 127 | if (balance + high == w / 2) |
145 | } /* end while */ | 128 | break; |
146 | STOP_LOOP | 129 | else if (balance + high > w / 2) { |
130 | min = partition; | ||
131 | } /* end if */ | ||
132 | else { | ||
133 | max = partition; | ||
134 | high++; | ||
135 | } /* end else */ | ||
136 | } | ||
137 | if (min == max) | ||
138 | break; | ||
139 | } /* end else* */ | ||
140 | index = (partition + hops) % (f - w); | ||
141 | hops++; | ||
142 | } /* end loop ll */ | ||
143 | thread[l].hops = hops; | ||
144 | } /* end while */ | ||
145 | } | ||
147 | 146 | ||
148 | endTime = time(NULL); | 147 | endTime = time(NULL); |
149 | 148 | ||