Thread: Data Structures part2

  1. #1
    sonicsite
    Guest

    Data Structures part2

    Ive added this surrounded by (****) to the original program..but it still wont compile..please help

    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>

    #define MAXQUEUE 5

    typedef char QueueEntry;
    typedef struct queue
    {
    int count;
    int front;
    int rear;
    QueueEntry entry[MAXQUEUE];
    } Queue;

    void CreateQueue(Queue *);
    void Append(QueueEntry, Queue *);
    void Serve(QueueEntry *, Queue *);
    int QueueSize(Queue *);
    bool QueueEmpty(Queue *);
    bool QueueFull(Queue *);
    void Traverse Queue(Queue *, QueueEntry *x);
    void Error();
    *************************************************
    int main(void)
    {
    Queue queue;
    QueueEntry myentry;


    CreateQueue(queue);
    printf("Enter a letter for queue");
    scanf("%c",&mysentry);

    Append(myentry, queue);
    QueueSize(queue);
    printf("this is the queue %c",queue->entry);

    return 0;
    ************************************************** **
    }

    void CreateQueue(Queue *q)
    {
    q->count=0;
    q->front=0;
    q->rear=-1;
    }

    void Append(QueueEntry *x, Queue *q)
    {
    if (QueueFull(q))
    Error();
    else
    {
    q->count++;
    q->rear=(q->rear +1) %MAXQUEUE;
    q->entry[q->rear]= *x;

    }
    }

    void Serve(QueueEntry *x, Queue *q)
    {
    if (QueueEmpty(q))
    Error();
    else
    {
    q->count--;
    *x=q->entry[q->front];
    q->front=(q->front +1) %MAXQUEUE;
    }
    }

    int QueueSize(Queue *q)
    {
    return q->count;
    }

    bool QueueEmpty(Queue *q)
    {
    return q->count<=0;
    }

    bool QueueFull(Queue *q)
    {
    return q->count>=MAXQUEUE;
    }

    void TraverseQueue(Queue *q, QueueEntry *x)
    {
    int position;

    if (!QueueEmpty(q))
    {
    if (q->front <= q->rear)
    {
    for(position=q->front; position== q->rear; position++)
    }
    else
    {
    for(position=q->front; position==MAXQUEUE; position++)
    }
    }
    for (position=1; position==q->rear; position++)
    }

    void Error()
    {
    printf("Error");

    <!--StartFragment-->void TraverseQueue(Queue *q, QueueEntry *x)
    {
    int position;

    if (!QueueEmpty(q))
    {
    if (q->front <= q->rear)
    {
    for(position=q->front; position== q->rear; position++)
    }
    else
    {
    for(position=q->front; position==MAXQUEUE; position++)
    }
    }
    for(position=1; position==q->rear; position++)
    <!--EndFragment-->

  2. #2
    Unregistered
    Guest

    Smile

    For starters.

    scanf("%c",&mysentry);

    should be:

    &myentry &mySentry does not exist.

  3. #3
    Unregistered
    Guest

    Wink

    Sonicsite,


    Go to a university library and look at C data structure texts. They have queues(link list and array based). I have 2 C data structure texts like this. modify the authors code in the text and you will have it.

    Let me know and can give you some good C data structure texts.

    Mr. C

    C, C++ and Java instructor

  4. #4
    Sayeh
    Guest
    For another thing:

    Code:
    int main(void) 
    { 
    Queue queue; 
    QueueEntry myentry; 
    
    ...
    You can't create a variable named 'queue'-- you already declared a forward declaration of your 'Queue' structure as 'queue'. You can't have both.

    Change your variable name to 'myQueue', or something.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    umm...

    actually... sayeh...
    he can why? there is a large difrence between "Queue" and "queue"...

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > he can why? there is a large difrence between "Queue" and "queue"...

    Because of this:
    typedef struct queue

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    5
    you think that ive looked throught these biiiiig code? i just looked at what sayeh sayed

  8. #8
    Unregistered
    Guest
    when passing your functins shouldn' t you use
    CreateQueue(&myQueue);//function call
    all your functions are recieving pointers to Queues so if i am corredt you should pass the address to these functions when making a call
    Append(x,&q);//function call

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a good generalized data structures book?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-16-2006, 01:01 PM
  2. i need advice about data structures
    By sawer in forum C Programming
    Replies: 2
    Last Post: 04-22-2006, 03:40 AM
  3. Data Structures C++ Book
    By Cprogrammer in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2005, 12:50 AM
  4. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 01:42 PM
  5. Array Data Structures
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 06:52 PM