Solved

Questions about QUEUE...

Posted on 1998-12-09
5
204 Views
Last Modified: 2012-05-04
Here questions about QUEUE, can give your suggest answer??:
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.
0
Comment
Question by:tagheuer
5 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 1254982
Is it homework assignment?
0
 
LVL 1

Expert Comment

by:billyh
ID: 1254983
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
 

Expert Comment

by:bflVijay
ID: 1254984
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
 

Expert Comment

by:jit1
ID: 1254985
It's better to scratch ur head and try urself first.
I think u can easily find the solution to ur problem
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 20 total points
ID: 1254986
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
eg. int head, tail

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 add an entry at queue[head]=entry then do head++;head%=MAXQUEUE;

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question