projects
/
openpower-isa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
f1fae05
)
fix maxloc
author
Luke Kenneth Casson Leighton
<lkcl@lkcl.net>
Tue, 14 Nov 2023 11:58:09 +0000
(11:58 +0000)
committer
Luke Kenneth Casson Leighton
<lkcl@lkcl.net>
Tue, 14 Nov 2023 11:58:09 +0000
(11:58 +0000)
maxloc/maxloc.c
patch
|
blob
|
history
diff --git
a/maxloc/maxloc.c
b/maxloc/maxloc.c
index e37160c65b8947811d56eee4b5cea7215263299e..f0786e734d9167ae133094812b89cf18328600ba 100644
(file)
--- a/
maxloc/maxloc.c
+++ b/
maxloc/maxloc.c
@@
-1,23
+1,22
@@
-#include<stdio.h>
+#include
<stdio.h>
int m2(int *a, int n)
{
- int m, nm;
- int i;
+ int m = 0;
+ int nm = -1;
+ int i = 0;
- m = 0;
- nm = -1;
- i=0;
while (i<n) {
while (i<n && a[i]<=m) {
printf("%d idx %d <= m %d\n", i, a[i], m);
i++;
}
- if (a[i] > m) {
- m = a[i];
- nm = i;
- }
- i++;
+ while (i < n && a[i] > m) {
+ printf("%d idx %d > m %d\n", i, a[i], m);
+ m = a[i];
+ nm = i;
+ i++;
+ }
}
return nm;
}