?
Solved

Questions about QUEUE...

Posted on 1998-12-09
5
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 40 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

764 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