queue

This is a discussion on queue within the C Programming forums, part of the General Programming Boards category; i dont know if my question was worded properly before, what i need to do is: Enter several values and ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Question queue

    i dont know if my question was worded properly before, what i need to do is:

    Enter several values and store them in a queue
    display the highest value in the structure

    all i need really is how to display the the highest value, im having major problems with this, so if you could help me i would be very grateful.



    Who is your daddy and what does he do

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know what a queue actually is? Hell, if all you care about is the ___ value, then you just have to make sure it always stays on top.

    NODE *myList;

    ...some value is inserted to a node in the list...
    ...some new value is inserted into 'newnode'...
    Code:
    if( newNode->value < myList-> value )
    {
       newNode->next = myList->next;
       myList->next = newNode;
    }
    else
    {
       newNode->next = myList;
       myList = newNode;
    }
    What seems to be the problem? You don't even need a double linked list for this.

    You could just as easily use an array for your queue.

    Quzah.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    6
    thanx. im meant to use a queue to do this, an ADT priority queue, im not allowed to use linked list. Im a pretty bad programmer, so im not sure whats goin on :P.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    6
    what i have to do i enter details store them in a queue then displa the values in order of priority i.e highest number first. im not meant to use linked lists, but ADT queue. thanx

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So use an array:
    Code:
    int arrayOfValues[SIZE];
    int highestValueIndex;
    int arrayCount;
    
    /* add the new value to the array */
    arrayOfValues[arrayCount] = newValue;
    
    /* check highest value */
    if( newValue > arrayOfValues[highestValueIndex] )
       highestValueIndex = arrayCount; /* fix highest value index */
    
    /* increment count */
    arrayCount++;
    Simple stuff.

    Quzah.

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Talking

    thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 10:09 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 12:39 PM
  5. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 09:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21