-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctmfila.c
89 lines (73 loc) · 1.98 KB
/
ctmfila.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "ctmfila.h"
#include "musica.h"
struct desc_queue *criaDescQueue(void){
struct desc_queue *queue = (struct desc_queue*)malloc(sizeof(struct desc_queue));
queue->head = NULL;
queue->tail = NULL;
queue->tamanho=0;
return queue;
}
struct nodo_queue *criaNodoQueue(struct music *musica){
struct nodo_queue *novoNodo = (struct nodo_queue*)malloc(sizeof(struct nodo_queue));
novoNodo->info = musica;
novoNodo->prox = NULL;
return novoNodo;
}
void enqueue(struct desc_queue *queue, struct nodo_queue *novoElemento){
if(empty_queue(queue) == 1){
queue->head = novoElemento;
queue->tail = novoElemento;
}
else{
queue->tail->prox = novoElemento;
queue->tail = novoElemento;
}
queue->tamanho++;
}
struct nodo_queue *dequeue(struct desc_queue *queue){
struct nodo_queue *aux = queue->head;
if(queue->tamanho > 0){
queue->head = queue->head->prox;
queue->tamanho--;
}
return aux;
}
int empty_queue(struct desc_queue *queue){
if(queue->head == NULL)
return 1;
else
return 0;
}
int length(struct desc_queue *queue){
return queue->tamanho;
}
void makeNull(struct desc_queue *queue){
while(empty_queue(queue) == 0){
free(dequeue(queue));
}
}
struct nodo_queue* head(struct desc_queue *queue){
return queue->head;
}
void showQueue(struct desc_queue *queue){
struct nodo_queue* topo = head(queue);
if(topo == NULL)
printf("vazia!\n");
while(topo != NULL){
printf("\n[titulo: %s\nartista: %s\nletra: %s\ncodigo: %i\nexecucoes: %i]\n",topo->info->title, topo->info->artist, topo->info->lyrics, topo->info->code, topo->info->exe);
topo = topo->prox;
}
}
struct music *criaMusicQueue(int execucoes, int codigo, char artista[], char titulo[], char letra[]){
struct music *musica = (struct music*)malloc(sizeof(struct music));
strcpy(musica->artist, artista);
strcpy(musica->title, titulo);
strcpy(musica->lyrics, letra);
musica->exe = execucoes;
musica->code = codigo;
return musica;
}