[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [bug-gawk] How to mimic inserting an element to a vector?

**From**: |
Peng Yu |

**Subject**: |
[bug-gawk] How to mimic inserting an element to a vector? |

**Date**: |
Thu, 11 Jul 2019 12:09:51 -0500 |

Hi,
I use the following code to mimic inserting an element to a vector
(i.e, the keys are 1,2,...). But it is a little cumbersome. Is there
any implement that is better?
function insert(a, i, v) {
for(k in a) {
if(k>=i) {
a[k+1] = a[k]
}
}
a[i] = v
}
BEGIN {
for(i=1;i<=3;++i) {
a[i] = 100 + i
}
PROCINFO["sorted_in"] = "@ind_num_desc"
insert(a, 2, 2)
PROCINFO["sorted_in"] = "@ind_num_asc"
for(k in a) {
print k, a[k]
}
}
--
Regards,
Peng

**[bug-gawk] How to mimic inserting an element to a vector?**,
*Peng Yu* **<=**