Data Structures

This is a discussion on Data Structures within the C Programming forums, part of the General Programming Boards category; are these correct: void ClearQueue(Queue *q) { q->count = 0; q->front = 0; q->rear = - 1; } void QueueFront(QueueEntry ...

  1. #1
    sonicsite
    Guest

    Question Data Structures

    are these correct:

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



    void QueueFront(QueueEntry *x, Queue *q)
    {
    if (QueueEmpty(q))
    Error('Queue is empty.");
    else{
    q->entry[q->front] = x;
    }
    }

    void TraverseQueue(Queue(Queue *q, void (*Visit)(QueueEntry x));
    {
    int i;
    for(i = 0; i < q->entry; i++)
    *visit(q->entry[i];
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    void TraverseQueue(Queue(Queue *q, void (*Visit)(QueueEntry x));
    {
    int i;
    for(i = 0; i < q->entry; i++)
    *visit(q->entry[i];
    }


    This will not compile.

    PHP Code:
    void TraverseQueueQueue *qvoid (*Visit)(QueueEntry x)); 

        for( 
    int i 0q->entry i++) Visitq->entry[i] ); 

    This might.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Code:
    void QueueFront (QueueEntry *x, Queue *q) 
    { 
        if (QueueEmpty (q)) 
            Error('Queue is empty."); 
        else
            q->entry[q->front] = x; 
    }
    If QueueEntry is an integer, and q->entry [i] is also an integer, then q->entry[q->front]=x should be q->entry[q->front]=*x;

    Can you give the specifications of the functions? To me it seems that x is in output variable. So I would expect:

    Code:
    void QueueFront (QueueEntry *x, Queue *q) 
    { 
        if (QueueEmpty (q)) 
            Error('Queue is empty."); 
        else
            *x = q->entry[q->front]; 
    }
    It's just a matter of interpretation. But what I mean is: please make clear what your programs do, perhaps using pre- and postconditions, and show us what your datatypes are. Queue doesn't tell us very much. Though I guess it's a structure with an array and some variables in it.

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, 12: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. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 04:19 AM
  4. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 12:42 PM
  5. Array Data Structures
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 05:52 PM

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