Thread: queues

  1. #1
    Unregistered
    Guest

    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.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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.

  3. #3
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    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

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. posix queues
    By chaitra1604 in forum Linux Programming
    Replies: 1
    Last Post: 03-13-2009, 03:35 PM
  2. Concatenating two static queues?
    By difficult.name in forum C Programming
    Replies: 2
    Last Post: 10-18-2004, 11:19 PM
  3. stacks and queues
    By j0hnb in forum C Programming
    Replies: 4
    Last Post: 04-16-2003, 09:44 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  5. queues
    By jamesb in forum C Programming
    Replies: 1
    Last Post: 04-21-2002, 08:57 PM