when using queues in a program is there a particular library that can be used to make it less time consuming? And what all is necessary to begin writing queues.
when using queues in a program is there a particular library that can be used to make it less time consuming? And what all is necessary to begin writing queues.
Hmm. Well, first I'll say that there is not any standard library to make using queues less time consuming, but you could just write one of your own. Consider making a queue using a linked list. Have one pointer at the first element of the list, and a pointer at the last element of the list. When you add an item to the queue, just add an item to the end of the list. When you need to pop an item off the queue, remove an item from the beginning of the list.
There are other ways to do queues, but that's a pretty good one.
the way i do queues is the following:
int* queue;
int* queuebegin;
int* queueend;
int size;
int totalsize;
void startqueue(int size)
{
queue=new(int[size]);
queuebegin=queue;
queueend=queue;
size=0;
totalsize=size; //this could be useful
}
void additem(int item)
{
*queue=item;
size=size+1;
}
int getitem()
{
if size>0
{
queueend=queueend+1;
return *(queueend-1);
}
return -1;
}
try this out, and you could make it a little smaller (i mean memory usage) by reusing the queue when queuestart reaches queue+totalsize, but I think you could work something out with this.
Good luck
Oskilian
Unregistered, how many threads do you HAVE that are asking for help with this programming assignment of yours? People aren't going to write your homework for you, and posting at least three times isn't going to make people want to help you.
Get as far as you can on your own, post what you have, and people will help you. But if you expect people to do your project for you, you are gonna be disappointed.
And, if you can't make ANY progress on the project, you should drop the class, because you're obviously not learning the material.