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
Solved

Questions about QUEUE...

Posted on 1998-12-09
5
208 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

856 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