Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "queue.h"
- Queue* createQueue(int capacity)
- {
- Queue* queue=(Queue*)malloc(sizeof(Queue));
- queue->capacity=capacity;
- queue->head=0;
- queue->tail=0;
- queue->data=(char**)malloc(queue->capacity*(sizeof(char*)));
- for(int i=0;i<queue->capacity;i++)
- queue->data[i]=(char*)malloc(sizeof(char)*640);
- return queue;
- }
- Queue* createQueueClients(int capacity)
- {
- Queue* queue=(Queue*)calloc(1, sizeof(Queue));
- queue->capacity=capacity;
- queue->head=0;
- queue->tail=0;
- queue->CurrentSize=0;
- queue->MaxElement=capacity;
- queue->Tab = (int*)calloc(capacity, sizeof(int));
- return queue;
- }
- unsigned int size(Queue* queue)
- {
- return queue->head-queue->tail;
- }
- unsigned int capacity(Queue * queue)
- {
- return queue->capacity;
- }
- void push(Queue* queue,char* data)
- {
- unsigned int index = queue->head % queue->capacity;
- if(size(queue) == capacity(queue))
- queue->tail++;
- queue->head++;
- queue->data[index]=data;
- }
- char *pop(Queue* queue)
- {
- unsigned int index = queue->tail % queue->capacity;
- queue->tail++;
- return queue->data[index];
- }
- void pushClients(Queue* queue, int x)
- {
- queue->Tab[queue->tail] = x;
- queue->tail = (queue->tail+1) % queue->MaxElement;
- queue->CurrentSize++;
- }
- int popClients(Queue* queue)
- {
- int x = queue->Tab[queue->head];
- queue->Tab[queue->head] = '\0';
- queue->head = (queue->head+1) % queue->MaxElement;
- queue->CurrentSize--;
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement