• C

1st question:
Write the functions needed for the implementation of queues in a linear array when it can be assumed that the queue can be
emptied when necessary.
Write a function Append that will add an entry if there is room and, if not, will call another function ServeAll(Queue *Q) that
will empty queue. While writing this second function, you may assume the existence of an auxiliary function Service(QueueEntry
x) that will process a single entry that you have just removed from the queue.

2nd question:
By creating nodes and freeing nodes, write functions
a.Append; and
b.Serve
that will process entries for linked queues and that can be substituted directly for their contiguous counterparts.

3rd question:
Write the following C functions for linked queues.
a.QueueEmpty
b.ClearQueue
c.QueueFront
d.QueueFrontNode
QueueFrontNode returns a pointer to the node at the front of the queue, whereas QueueFront returns a copy of the front
entry.

Any way Thank You for helping.
###### Who is Participating?

Commented:
Doing your homework for you is worth more than 20 points ... actually noone here will do it for you anyway.

But I can give you some pointers...

>1st question:
>Write the functions needed for the implementation of queues in
>a linear array when it can be assumed that the queue can be
>emptied when necessary.

#define the max number of entries in the queue
eg #define MAXQUEUE 20

create an array with that number of entries
eg. QueueEntry queue[MAXQUEUE]

maintain two int variables that keep track of the head and tail of the queue

put all these in a struct called Queue

init them to both be zero (empty queue)

you will check for an empty queue with head==tail

you will check for a full queue with (head+1)%MAXQUEUE==tail

you will remove an entry with entry=queue[tail] then do tail++;tail%=MAXQUEUE; (check for empty queue first)

>Write a function Append that will add an entry if there is room
>and, if not, will call another function ServeAll(Queue *Q) that
>will empty queue. While writing this second function, you may
>assume the existence of an auxiliary function Service
>(QueueEntry x) that will process a single entry that you have
>just removed from the queue.

should be easy one you have the above implemented

>2nd question:
>By creating nodes and freeing nodes, write functions
>   a.Append; and
>   b.Serve
>that will process entries for linked queues and that can be >substituted directly for their contiguous counterparts.

here you would create a double linked list (next and prev pointers) of QueueEntry objects.  You'd maintain a head and tail pointer to the doubly linked list.

To add an entry, allocate a new list item and add it to the head of the list.  To remove, get a copy of the item in the tail of the list, remove the tail from the list and free it

>3rd question:
>Write the following C functions for linked queues.
>   a.QueueEmpty
>   b.ClearQueue
>   c.QueueFront
>   d.QueueFrontNode
>QueueFrontNode returns a pointer to the node at the front of
>the queue, whereas QueueFront returns a copy of the front
>entry.

You'd probably do this to implement 2 above

0

Commented:
Is it homework assignment?
0

Commented:
I agree with you pagladasu, http:tagheuer problem seem more like an assignment.

I could help with ideas, but I would not code your assignment. So tell us what giving you a headache in your assignment.
0

Commented:
As billyh says, would ideas be OK? Or do you want the full code?
If so, perhaps I could help. Or why don't you try a standard book on Data Structures (You would get the full code as you want).
0

Commented:
It's better to scratch ur head and try urself first.
I think u can easily find the solution to ur problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.