Solved

Questions about QUEUE...

Posted on 1998-12-09
5
201 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
Comment Utility
Is it homework assignment?
0
 
LVL 1

Expert Comment

by:billyh
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now