1

Here's my problem: I need to implement a FIFO/LIFO list stack as ADT species 1. My program is modular and it have an item.h module:

    #ifndef ITEM_H_INCLUDED
    #define ITEM_H_INCLUDED

    typedef struct
    {
        char stringa[20];
        int numero;
    } Item;        
    #endif // ITEM_H_INCLUDED

The head.h module:

#ifndef HEAD_H_INCLUDED
#define HEAD_H_INCLUDED

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

#include "item.h"  

void QUEUEinit();
int QUEUEempty();
void QUEUEput_top(Item);
void QUEUEput_bottom(Item);
Item QUEUEget_top();
Item QUEUEget_bottom();

#endif // HEAD_H_INCLUDED

The main.c and data.c; what i need is how i declare a QEUEnode struct and where.

Thank you for the help :)

Randy Howard
  • 2,165
  • 16
  • 26
Lamberto Basti
  • 478
  • 1
  • 6
  • 24
  • I believe this post should answer your question. http://stackoverflow.com/questions/252780/why-should-we-typedef-a-struct-so-often-in-c – AlexLordThorsen Apr 30 '13 at 16:18
  • more or less, but it does not deal with the pointers. What i need is to declare te pointer of the QUEUEnode in the header, and then define te structure in the data.c – Lamberto Basti Apr 30 '13 at 16:26
  • So by "declare the pointers of the QUEUEnode" do you mean set up your functions to pass QUEUEnode pointers? – AlexLordThorsen Apr 30 '13 at 16:29
  • i'm sorry, i badly explained; what i need is how i declare a structure inside the module data.c, and his pointer in head.h – Lamberto Basti Apr 30 '13 at 16:46

1 Answers1

1

Since none of your QUEUE* functions receive a QUEUEnode *, you can hide it in the head.c file, along with the QUEUEnode root; that they operate on.

If you want to use multiple queues, then it should probably be in the head.h file so they can be created in main.c. For this, you'll also need to modify the functions to accept a queue to operate on.

luser droog
  • 18,988
  • 3
  • 53
  • 105