what is the prog coding for this question and what it output

M

mohd hisham

Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

i hope u guys can help me,for me it is difficult question.
 
I

infobahn

mohd said:
Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

Which do you mean? Queues are generally LIFO. Stacks are generally FIFO.
i hope u guys can help me,for me it is difficult question.

I can get you started, but you'll need to fill in the blanks.

#include <stdio.h>

int insert(void *p)
{
return 0;
}

int delete(void *p)
{
return 0;
}

int display(void *p)
{
return 0;
}

int main(void)
{
insert(NULL);
delete(NULL);
display(NULL);
return 0;
}
 
J

John Valko

mohd said:
Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

i hope u guys can help me,for me it is difficult question.

It appears you've forgotten to post the code you've written so far to
ask about. Post it and then perhaps you can get some help.
 
M

Mike Wahler

mohd hisham said:
Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

i hope u guys can help me,for me it is difficult question.

If you contact me privately and agree upon a pay
rate, I'll certainly write it for you (if you can
convince me this isn't a homework assignment).

However, if you try to write it yourself, but get stuck,
and post your code along with specific questions,
I (and I suspect many others) will help you for free.

-Mike
 
K

Keith Thompson

mohd hisham said:
Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

Give us your instructor's e-mail address; we'll just send it to him
directly.
 
D

dandelion

infobahn said:
Which do you mean? Queues are generally LIFO. Stacks are generally FIFO.

Leave out "generally" and i'd agree. Insertions and deletions (at the
appropriate places) are legitimate operations in both.

I like your "skeleton" code. Should not be a problem to fill in the blanks.
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Which do you mean? Queues are generally LIFO. Stacks are generally FIFO.

ITYM "Queues are generally FIFO (First In, First Out). Stacks are
generally LIFO (Last In, First Out)"

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFB/4EuagVFX4UWr64RAnaWAJ9yCM1Os3sZy8doMbfL32kZyIUUTACgyNPr
5ZWrgs5yUjH1umN2csVUT2s=
=VL64
-----END PGP SIGNATURE-----
 
O

osmium

mohd hisham said:
Write a C program to construct a queue of integers and to perform the
following operations on it:
a. insert
b. delete
c. display
The program should print appropriate messages for stack overflow and stack
empty.

i hope u guys can help me,for me it is difficult question.

Try to get clarification on what is to be done. I don't think (I hope)
anyone whose native language is English and speaking carefully is likely to
put things quite that way. Insert usually means somewhere in the middle, as
in a linked list. Members added to a queue are added at one end and taken
off at the other end. Members are added to a stack at one end and taken off
at the same end. You can't delete a specified member of a stack. But the
concepts of overflow don't apply to a queue or to a linked list. It is true
you *could* run out of hardware, but that is an aberration, not something a
(neophyte) programmer would handle.

I realize that some people use the word "queue" for a linked list, but I
would never do that. To me a queue should connote a physical queue, as a
line of people waiting for a bus. A linked list is something that doesn't
exist in the real world, it's a programmer's invention. OTOH, a queue does
have a real world manifestation.

So, my synopsis: it's not a stack, it's not a queue, it's not a linked list.
What is it?
 
O

osmium

:

It's a deque. I kid you not.

Why does a double ended queue have overflow? As I said, you can run out of
hardware, but an application programmer doesn't usually consider this.
 
D

dandelion

osmium said:
:



Why does a double ended queue have overflow? As I said, you can run out of
hardware, but an application programmer doesn't usually consider this.

As the storage for the queue, you would normally use a predimensioned array,
which can be full adn hence, overflowed.

eg

int dequeue[Q_SIZE];

would overflow if more than Q_SIZE elements have been inserted.
 
O

osmium

dandelion said:
osmium said:
:



Why does a double ended queue have overflow? As I said, you can run out of
hardware, but an application programmer doesn't usually consider this.

As the storage for the queue, you would normally use a predimensioned
array,
which can be full adn hence, overflowed.

eg

int dequeue[Q_SIZE];

would overflow if more than Q_SIZE elements have been inserted.

Well, that strikes me as plain silly. You just flushed one of the main
advantages of the data structure right down the drain.

I have often modeled lists and stacks by use of an array. But I consider
those very light duty, not fit for general consumption. In my experience an
array is an especially easy way to make a stack, I usually have a handle on
the upper limit. For lists, in general, I have no decent guess to work
with.
 
R

Richard Bos

osmium said:
Members added to a queue are added at one end and taken
off at the other end. Members are added to a stack at one end and taken off
at the same end. You can't delete a specified member of a stack. But the
concepts of overflow don't apply to a queue or to a linked list. It is true
you *could* run out of hardware, but that is an aberration, not something a
(neophyte) programmer would handle.

Erm... he'd better. If checking for allocation failure is not something
you learn as you learn about allocation, it's very easy, too easy, to
get into the habit of never checking for allocation failure. With the
result that someday, your seventy-one gigs of database will go *poof*
because you weren't able to allocate the seventy-second gig.
I realize that some people use the word "queue" for a linked list, but I
would never do that. To me a queue should connote a physical queue, as a
line of people waiting for a bus. A linked list is something that doesn't
exist in the real world, it's a programmer's invention.

Tell that to a train driver. Or to a fencemaker.
So, my synopsis: it's not a stack, it's not a queue, it's not a linked list.
What is it?

A badly phrased homework problem.

Richard
 
R

Richard Bos

CBFalconer said:
It's a deque. I kid you not.

Not as osmium described it - he wrote of insertion in the middle. If
insert means "at either end", i.e., "push or put", and delete means "get
value from either end and remove that element", i.e., "pop, pull or
get", then yes.
I agree with osmium, though, that "insert" and "delete" are not the
terms one usually sees for those. They're more often used for general
linked lists, which a deque is not (not general, that is; it may be a
linked list of some kind, underneath).

Richard
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael said:
Lew said:
infobahn wrote: [snip]
Which do you mean? Queues are generally LIFO. Stacks are generally FIFO.

ITYM "Queues are generally FIFO (First In, First Out). Stacks are
generally LIFO (Last In, First Out)"

Think again.

I have. Why don't you?

It's not the definitive reference, but try
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=queue&action=Search
and
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=stack&action=Search





- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFB/7nbagVFX4UWr64RAiRfAJ9kwKFKDr84bjVJpKNIPybNadTBRQCcCRLO
+2+C/v4zHNbNzrVDVAOCGU0=
=JB+R
-----END PGP SIGNATURE-----
 
C

Chris Croughton

dandelion said:
osmium said:
Why does a double ended queue have overflow? As I said, you can run out of
hardware, but an application programmer doesn't usually consider this.

As the storage for the queue, you would normally use a predimensioned
array,
which can be full adn hence, overflowed.

eg

int dequeue[Q_SIZE];

would overflow if more than Q_SIZE elements have been inserted.

Well, that strikes me as plain silly. You just flushed one of the main
advantages of the data structure right down the drain.

It depends why and how you want to use it. A deque using a circular
fixed-size buffer can be very useful in some circumstances (a
flow-controlled input buffer where a character can be "pushed back", for
instance). Or a queue of processes to be run where the number of
processes in the system is fixed.
I have often modeled lists and stacks by use of an array. But I consider
those very light duty, not fit for general consumption.

Perhaps yours were. I've seen plenty in embedded real-time systems in
the Real World(tm). For that matter a number of Unix systems have
fixed-size stacks per process (and even one which isn't thought of as
fixed size will have a limit in practice, even if it's several
gigabytes).
In my experience an array is an especially easy way to make a stack, I
usually have a handle on the upper limit. For lists, in general, I
have no decent guess to work with.

Plenty of applications do have more than a "decent guess" to work with,
especially in embedded systems where resources are strictly limited so
that the behaviour is known (limited number of tasks and message queues,
for example).

Chris C
 

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
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top