Home > Net >  cleanQueue - cleanup function. C
cleanQueue - cleanup function. C

Time:11-03

Hi so I have a task to create a full queue with integers I need to do a clean function like that:

`void cleanQueue(Queue* q);
`

The Queue form is that:

typedef struct Queue
{
  int * arr;
} Queue;


Thanks alot!

CodePudding user response:

Well if you need the implemenatation to be like:

typedef struct Queue
{
  int * arr;
} Queue;

you could simply do:

void cleanQueue(Queue* q)
{
  delete q->arr;
}

or if you initialise the arr data member as an array like {1, 2, 3, 4}you would do it like this;

void cleanQueue(Queue* q)
{
  delete[] q->arr;
}

So you're program would be:

typedef struct Queue
{
  int * arr;
} Queue;

void cleanQueue(Queue* q)
{
    delete q->arr;
}

int main()
{
    // ... Do something
}

Basically what is happening is you are accessing the arr of the Queue using the -> operator and deleting the pointer to int: int* arr.

  • Related