quite confusion in function name.

T

Tinku

I made a FIFO (queue) through singly link-list, but i am confuse about
naming of these function -

int enqueue(struct queue * , struct queue_node *);
struct queue_node* dequeue(struct queue *);

can i use name "enqueue and dequeue"?
actually these names are related with double-ended queue and my queue
is simple
FIFO. Before using these name i was using "push and pop" but these
words are
also related with stack (LIFO), so i think i should not use these
words in
queue, now what name should I use to my function which pushing into
rear and poping from front. please suggest me.
 
E

Eric Sosman

Tinku said:
I made a FIFO (queue) through singly link-list, but i am confuse about
naming of these function -

int enqueue(struct queue * , struct queue_node *);
struct queue_node* dequeue(struct queue *);

can i use name "enqueue and dequeue"?

Yes. Or enq() and deq(), or add() and get(), or
ham() and eggs(). None of these names is reserved; all
are available to you.
actually these names are related with double-ended queue and my queue
is simple
FIFO. Before using these name i was using "push and pop" but these
words are
also related with stack (LIFO), so i think i should not use these
words in
queue, now what name should I use to my function which pushing into
rear and poping from front. please suggest me.

For a general double-ended "deque" you need four operations:
insert (at either end) and remove (from either end). A queue
uses only two of these (insert at one end, remove at the other),
and a stack uses only two (insert and remove at the same end).
To generate the four names you need, adopt a pair of terms for
insertion and removal -- add and rem, or ins and del, or some
such pair -- and another pair for the two ends -- top and bot,
lft and rgt, head and tail, whatever. Then glue them together
to get names for your four operations, like addtop(), addbot(),
remtop(), rembot(), or maybe lftins(), lftdel(), rgtins(),
rgtdel() -- whatever seems most natural.

For a deque operating as a stack or as a queue, "which end"
is implicit and needn't be expressed in the name. So it's
customary to use the verb alone, as in add() and del(), or
insert() and remove(), or give() and take(), or something of
that kind. The names push() and pop() are so frequently used
with stacks that I'd discourage you from using them with any
other data structure; it would just confuse people.

Of course, you *could* just name your four operations
bob() and carol() and ted() and alice() if you felt like it.
Don't expect sympathy, though.
 
L

luserXtrog

I made a FIFO (queue) through singly link-list, but i am confuse about
naming of these function -

int enqueue(struct queue * , struct queue_node *);
struct queue_node*  dequeue(struct queue *);

can i use name "enqueue and dequeue"?
actually these names are related with double-ended queue and my queue
is simple
FIFO. Before using these name i was using "push and pop" but these
words are
also  related with stack (LIFO), so i think i should not use these
words in
queue, now what name should I use to my function which pushing into
rear and poping from front. please suggest me.

There may be better ideas out there, but I've adopted the PERL
terms for each of these.
shift - remove and return first element
unshift - add new element to front
pop - remove and return last element
push - add new element to end

hth
 
R

Richard Bos

Eric Sosman said:
For a deque operating as a stack or as a queue, "which end"
is implicit and needn't be expressed in the name. So it's
customary to use the verb alone, as in add() and del(), or
insert() and remove(), or give() and take(), or something of
that kind. The names push() and pop() are so frequently used
with stacks that I'd discourage you from using them with any
other data structure; it would just confuse people.

I once saw a queue-cum-stack implementation (Snippets, IIRC, BICBW)
which used push() for inserting an item on one end, pop() for removing
it from the same and, and pull() for removing it from the other end. It
works as far as it goes, but the real problem is, of course: do you
allow inserting at the other end as well, and if so, what on earth do
you call it? shove()?

Richard
 
K

Keith Thompson

I once saw a queue-cum-stack implementation (Snippets, IIRC, BICBW)
which used push() for inserting an item on one end, pop() for removing
it from the same and, and pull() for removing it from the other end. It
works as far as it goes, but the real problem is, of course: do you
allow inserting at the other end as well, and if so, what on earth do
you call it? shove()?

Perl uses push and pop for the tail, unshift and shift for the head.
 
E

Eric Sosman

Richard said:
I once saw a queue-cum-stack implementation (Snippets, IIRC, BICBW)
which used push() for inserting an item on one end, pop() for removing
it from the same and, and pull() for removing it from the other end. It
works as far as it goes, but the real problem is, of course: do you
allow inserting at the other end as well, and if so, what on earth do
you call it? shove()?

I'd wonder which of pop() and pull() was at the same end
as push() ... Maybe if I used the names long enough and their
age withered and custom staled I'd find a way to remember.

Not long ago I came across a deque that ran with insertions
at one end only and removals at both: stack-like or queue-like,
depending on which removal got there first. The names used were
push(), poptop(), and popbot(), the idea being that the "top"
of the [stack if that's how I'm using it] was the same end that
push() operated on, hence "bot" was the [queue-like] other.

Maybe conquest(), war(), famine(), and death() are pretty
reasonable names, after all ... Just be sure to steer clear
of issue() and strip() and tokentake().
 
L

luserXtrog

Richard Bos wrote:
I once saw a queue-cum-stack implementation (Snippets, IIRC, BICBW)
which used push() for inserting an item on one end, pop() for removing
it from the same and, and pull() for removing it from the other end. It
works as far as it goes, but the real problem is, of course: do you
allow inserting at the other end as well, and if so, what on earth do
you call it? shove()?

     I'd wonder which of pop() and pull() was at the same end
as push() ...  Maybe if I used the names long enough and their
age withered and custom staled I'd find a way to remember.

     Not long ago I came across a deque that ran with insertions
at one end only and removals at both: stack-like or queue-like,
depending on which removal got there first.  The names used were
push(), poptop(), and popbot(), the idea being that the "top"
of the [stack if that's how I'm using it] was the same end that
push() operated on, hence "bot" was the [queue-like] other.

     Maybe conquest(), war(), famine(), and death() are pretty
reasonable names, after all ...  Just be sure to steer clear
of issue() and strip() and tokentake().

Can't we safely assume that since 'sue' is not an english term
for a character class, 'ip' not a term for a string operation,
and 'kentake' not even a word at all, that the standard does not
intend to prohibit these identifiers?
 
R

Richard Bos

Eric Sosman said:
I'd wonder which of pop() and pull() was at the same end
as push() ... Maybe if I used the names long enough and their
age withered and custom staled I'd find a way to remember.

pop() at the same end as push(), of course (as, I see, I did mention).
push() and pop() for a stack, push() and pull() for a queue.
Maybe conquest(), war(), famine(), and death() are pretty
reasonable names, after all ...

With the proviso that most people would prefer pestilence() to
conquest().

(And remember, Famine first, then Death, Pestilence last. And whatever
you do, don't eat their corpses.)

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top