J
jjh5030
This is a programming assignment. You are asked to work with pointers.
Be aware that error messages are often not very helpful when your
pointers
point to bad locations. Therefore, reserve additional time for
debugging.
Implement a data structure Extended Queue using pointers. In addition
to the usual queue operations Enqueue(x), Dequeue and the trivial
operations
Make-empty-queue and the Is-empty test, you are asked to have
two nonstandard operations.
· High-priority-enqueue(x) enqueues x at the front of the queue.
· Medium-priority-enqueue(x) enqueues x in the middle. If the sequence
has odd length, then x is enqueued just before the middle.
The elements x of the Extended Queue are integers.
Pointers are often used for fast algorithms. We use pointers here,
because
we require that each of the Extended Queue operations is done in
(worst
case) time O(1).
(a) Describe how you achieve time O(1) for the operation Medium-
priorityenqueue(
x).
(b) Write a program implementing Extended Queue as follows. It starts
building an empty Extended Queue. Then it reads standard input
without any prompts until it reaches end-of-file. The input is a
sequence
of commands (one command per line) of the form:
· e x (for Enqueue(x))
· h x (for High-priority-enqueue(x))
· m x (for Medium-priority-enqueue(x))
· d (for Dequeue)
After reading any command, that command is executed in time O(1).
On Dequeue, the dequeued element is output. When eof is reached in
the input, then start a new line and do Dequeue until the Extended
Queue is empty.
(c) Run your program on the Command File below
e 1
h 2
m 3
m 4
m 5
d
h 6
d
d
d
m 7
h 8
h 9
m 10
d
d
m 11
e 12
e 13
m 14
can anyone help me out?
Be aware that error messages are often not very helpful when your
pointers
point to bad locations. Therefore, reserve additional time for
debugging.
Implement a data structure Extended Queue using pointers. In addition
to the usual queue operations Enqueue(x), Dequeue and the trivial
operations
Make-empty-queue and the Is-empty test, you are asked to have
two nonstandard operations.
· High-priority-enqueue(x) enqueues x at the front of the queue.
· Medium-priority-enqueue(x) enqueues x in the middle. If the sequence
has odd length, then x is enqueued just before the middle.
The elements x of the Extended Queue are integers.
Pointers are often used for fast algorithms. We use pointers here,
because
we require that each of the Extended Queue operations is done in
(worst
case) time O(1).
(a) Describe how you achieve time O(1) for the operation Medium-
priorityenqueue(
x).
(b) Write a program implementing Extended Queue as follows. It starts
building an empty Extended Queue. Then it reads standard input
without any prompts until it reaches end-of-file. The input is a
sequence
of commands (one command per line) of the form:
· e x (for Enqueue(x))
· h x (for High-priority-enqueue(x))
· m x (for Medium-priority-enqueue(x))
· d (for Dequeue)
After reading any command, that command is executed in time O(1).
On Dequeue, the dequeued element is output. When eof is reached in
the input, then start a new line and do Dequeue until the Extended
Queue is empty.
(c) Run your program on the Command File below
e 1
h 2
m 3
m 4
m 5
d
h 6
d
d
d
m 7
h 8
h 9
m 10
d
d
m 11
e 12
e 13
m 14
can anyone help me out?