help with queues

This is a discussion on help with queues within the C Programming forums, part of the General Programming Boards category; Ive spent about 5 hours trying to put this together and I get nothing for my effort. Maybe Im just ...

  1. #1
    Unregistered
    Guest

    help with queues

    Ive spent about 5 hours trying to put this together and I get nothing for my effort. Maybe Im just a beginner who shouldnt be in this class. Can anyone help me on getting this queue project to work.And if you dont want to help do you know where i can learn more about queues . THanx.
    Here is the code:

    Code:
    #include <stdio.h> 
    #include <stdlib.h> 
    #include "queues.h" 
    
    /*Que ADT type definition*/ 
    
    typedef struct node 
    { 
    void *dataPtr; 
    struct node *next; 
    } QUEUE_NODE; 
    
    typedef struct 
    { 
    QUEUE_NODE *front; 
    QUEUE_NODE *rear; 
    int count; 
    } QUEUE; 
    
    /*prototype declarations*/ 
    QUEUE *createQueue (void); 
    QUEUE *destroyQueue (QUEUE *queue); 
    
    int dequeue (QUEUE *queue, void **itemPtr); 
    int enqueue (QUEUE *queue, void *itemPtr); 
    int queueFront (QUEUE *queue, void **itemPtr); 
    int queueRear (QUEUE *queue, void **itemPtr); 
    int queueCount (QUEUE *queue); 
    
    int emptyQueue (QUEUE *queue); 
    int fullQueue (QUEUE *queue); 
    
    /*End of Queue ADT defintions*/ 
    
    int main (void) 
    { 
    char letter; 
    
    printf("Choose a function to perform\n" 
    "A. Enqueue data into queue\n" 
    "B. Dequeu and print data\n" 
    "C. Print data at the front\n" 
    "D. Print data at the rear\n" 
    "E. Print entire queue\n" 
    "F. Print queue status: Empty\n" 
    "G. Print queue status: Full\n" 
    "H. Print number of element in queue\n" 
    "I. Destroy queue and quit\n"); 
    scanf("%c",&letter); 
    
    
    
    switch(letter) 
    { 
    case 'A'rintf("Enqueue data into queue\n");break; 
    case 'B'rintf("Dequeu and print data\n");break; 
    case 'C'rintf("Print data at the front\n");break; 
    case 'D'rintf("Print data at the rear\n");break; 
    case 'E'rintf("Print entire queue\n");break; 
    case 'F'rintf("Print queue status: Empty\n");break; 
    case 'G'rintf("Print queue status: Full\n");break; 
    case 'H'rintf("Print number of element in queue\n");break; 
    case 'I'rintf("Destroy queue and quit\n");break; 
    defaultrintf("bad choice\n"); 
    } 
    
    return 0; 
    } 
    /*createQueue*/ 
    QUEUE *creatQueue (void) 
    { 
    QUEUE *queue; 
    
    queue = (QUEUE *) malloc (sizeof (QUEUE)); 
    if (queue) 
    { 
    queue->front = NULL; 
    queue->rear = NULL; 
    queue->count = 0; 
    } 
    return queue; 
    } 
    /*creatQueue*/ 
    
    /*enqueue*/ 
    int enqueue (QUEUE *queue, void *itemPtr) 
    { 
    QUEUE_NODE *newPtr; 
    
    if (!(newPtr = (QUEUE_NODE *)malloc(sizeof(QUEUE_NODE)))) 
    return 0; 
    newPtr->dataPtr = itemPtr; 
    newPtr->next = NULL; 
    
    if (queue->count ==0) 
    queue->front = newPtr; 
    else 
    queue->rear->next = newPtr; 
    
    (queue->count)++; 
    queue->rear = newPtr; 
    return 1; 
    } 
    /*enqueue*/ 
    
    /*dequeue*/ 
    int dequeue (QUEUE *queue, void **itemPtr) 
    { 
    QUEUE_NODE *deleteLoc; 
    
    if (!queue->count) 
    return 0; 
    *itmePtr = queue->front->dataPtr; 
    deleteLoc = queue->front; 
    if (queue->count == 1) 
    queue->rear = queue->front = NULL; 
    else 
    queue->front = queue->front->next; 
    (queue->count)--; 
    free (deleteLoc); 
    
    return 1; 
    } 
    /*dequeue*/ 
    
    /*queueFront*/ 
    int queueFront (QUEUE *queue, void **itemPtr) 
    { 
    if(!queue->count) 
    return 0; 
    else 
    { 
    *itemPtr = queue->front->dataPtr; 
    return 1; 
    } 
    } 
    /*queueFront*/ 
    
    /*queueRear*/ 
    int queueRear (QUEUE *queue, void **itemPtr) 
    { 
    if(!queue->count) 
    return 0; 
    else 
    { 
    *itemPtr = queue->rear->dataPtr; 
    return 1; 
    } 
    } 
    /*queueRear*/ 
    
    /*emptyqueue*/ 
    int emptyQueue (QUEUE *queue) 
    { 
    return (queue->count == 0); 
    } 
    /*emptyqueue*/ 
    
    /*fullQueue*/ 
    int fullQueue (QUEUE *queue) 
    { 
    QUEUE_NODE *temp; 
    
    if ( (temp = (QUEUE_NODE *)malloc (sizeof (QUEUE_NODE))) ) 
    { 
    free(temp); 
    return 0; 
    } 
    
    return 1; 
    } 
    /*fullQueue*/ 
    
    /*queueCount*/ 
    int queueCount ( QUEUE *queue) 
    { 
    return queue->count; 
    } 
    /*queueCount*/ 
    
    /*destroyQueue*/ 
    QUEUE *destroyQueue (QUEUE *queue) 
    { 
    QUEUE_NODE *deletePtr; 
    
    if (queue) 
    { 
    while (queue->front != NULL) 
    { 
    free (queue->front->dataPtr); 
    deletePtr = queue->front; 
    queue->front = queue->front->next; 
    free (deletePtr); 
    } 
    free (queue); 
    } 
    return NULL; 
    } 
    /*destroyQueue*/

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Just a small tip, when you post your code, post it straight from the text editor you use. This way when you put it in code tags the indentaion will remain intact.

    > do you know where i can learn more about queues .
    You could always try Google, or any of the various source code sites which offer downloads of typical programming projects.
    The world is waiting. I must leave you now.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int main (void) 
    { 
        char letter; 
    
        printf("Choose a function to perform\n" 
            "A. Enqueue data into queue\n" 
            "B. Dequeu and print data\n" 
            "C. Print data at the front\n" 
            "D. Print data at the rear\n" 
            "E. Print entire queue\n" 
            "F. Print queue status: Empty\n" 
            "G. Print queue status: Full\n" 
            "H. Print number of element in queue\n" 
            "I. Destroy queue and quit\n"); 
        scanf("%c",&letter); 
    
        switch(letter) 
        { 
            case 'A'rintf("Enqueue data into queue\n");break; 
            case 'B'rintf("Dequeu and print data\n");break; 
            case 'C'rintf("Print data at the front\n");break; 
            case 'D'rintf("Print data at the rear\n");break; 
            case 'E'rintf("Print entire queue\n");break; 
            case 'F'rintf("Print queue status: Empty\n");break; 
            case 'G'rintf("Print queue status: Full\n");break; 
            case 'H'rintf("Print number of element in queue\n");break; 
            case 'I'rintf("Destroy queue and quit\n");break; 
            defaultrintf("bad choice\n"); 
        } 
    
        return 0; 
    }
    Can anyone spot the problem with this code? (Omitting the fact that your case statement is incorrect because the forum ate the colon and the p from printf...)

    You know why you aren't getting anything? Because you DON'T DO ANYTHING OTHER THAN CALL PRINTF! Your program exits right after that.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Oh, by the way,
    http://www.cprogramming.com/cboard/s...threadid=18178
    Keep to one thread please.
    The world is waiting. I must leave you now.

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, 04:35 PM
  2. Concatenating two static queues?
    By difficult.name in forum C Programming
    Replies: 2
    Last Post: 10-19-2004, 12:19 AM
  3. stacks and queues
    By j0hnb in forum C Programming
    Replies: 4
    Last Post: 04-16-2003, 10:44 PM
  4. queues
    By jamesb in forum C Programming
    Replies: 1
    Last Post: 04-21-2002, 09:57 PM
  5. queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-11-2001, 06:19 PM

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