Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

awk code for stack and queue

1,165 views
Skip to first unread message

Frank Chen

unread,
Sep 27, 1993, 7:37:52 AM9/27/93
to
Anyone got awk code to implement stack/queue available?
Thanks!

-Frank
--
===============================================================================
| Chih-Hung Chen (Frank) | email: fr...@manua.gsfc.nasa.gov|
| General Sciences Corp.(SAIC) | fax : (301) 286-3221 |
| Software Development - SeaWiFS Data System| voice: (301) 286-9531 |
| System/Network SeaWiFS Project | |
| NASA/Goddard Space Flight Center | |
| Code 970.2 | |
| Greenbelt, Maryland 20771 | |
===============================================================================

Michael S. Zraly

unread,
Sep 28, 1993, 9:24:00 AM9/28/93
to
fr...@manua.gsfc.nasa.gov (Frank Chen) writes:
>Anyone got awk code to implement stack/queue available?

# assuming nawk/gawk -- write code inline if you can't do functions

# stack: Use an array and an integer index thusly:

function st_push(val) {
st_array[st_pos++] = val;
}

function st_pop() {
return (st_size() > 0) ? "ERROR" : st_array[--st_pos];
}

function st_size() {
return st_pos;
}

# queue: Use an array and an two integer indices thusly:

function qu_add(val) {
qu_array[qu_tail++] = val;
}

function qu_del() {
return (qu_size() > 0) ? qu_array[qu_head++] : "ERROR";
}

function qu_size() {
return (qu_tail - qu_head);
}

--
Mike Zraly Nothing takes the taste out of peanut
mzr...@cs.umb.edu butter quite like unrequited love.
-- Charlie Brown

jhe...@google.com

unread,
Dec 21, 2016, 8:26:45 PM12/21/16
to
There is a bug in the provided stack implementation. st_pop should have its conditional reversed:

return (st_size() > 0) ? st_array[--st_pos] : "ERROR";
0 new messages