I don't really understand why I've been getting this error : Unknown type name 'DATA'.
#include <stdio.h>
#include <stdlib.h>
typedef int DATA;
#include "PriorityQueue.h"
int main(){
int priority;
DATA value;
LINK *head;
createEmpty(&head);
add(&head, 1, 7);
checkIfEmpty(head);
add(&head, 5, 5);
add(&head, 3, 4);
deleteElement(&head, &priority, &value);
add(&head, 1, 3);
destroy(head);
createEmpty(&head);
add(&head, 10, 10);
return 0;
}
Main
#include <stdio.h>
#include <stdlib.h>
#include "PriorityQueue.h"
void add(LINK **head, int p, DATA v){
LINK *curr=(*head);
LINK *beforeCurr=(*head);
LINK *newElement=NULL;
if((*head)->priority==-1){
(*head)->priority=p;
(*head)->value=v;
}
else{
newElement=(LINK*)malloc(sizeof(LINK));
newElement->priority=p;
newElement->value=v;
newElement->next=NULL;
while(p>(curr->priority) && curr->next!=NULL){
beforeCurr=curr;
curr=curr->next;
}
if(curr->next==NULL && p>(curr->priority))
curr->next=newElement;
else if(curr==(*head)){
newElement->next=curr;
(*head)=newElement;
}
else{
beforeCurr->next=newElement;
newElement->next=curr;
}
}
}
void deleteElement(LINK **head, int *p, DATA *v){
LINK *curr=(*head);
LINK *currB=(*head);
while(curr->next!=NULL) {
currB=curr;
curr=curr->next;
}
currB->next=NULL;
(*p)=curr->priority;
(*v)=curr->value;
free(curr);
}
void checkIfEmpty(LINK *head){
if(head->priority==-1)
printf("Queue is empty\n\n");
else
printf("Queue is not empty\n\n");
}
void destroy(LINK *head) {
LINK *current;
LINK *next;
current=head;
while(current!=NULL){
next=current->next;
free(current);
current=next;
}
head=NULL;
}
void createEmpty(LINK **head) {
LINK *curr=NULL;
curr=(LINK*)malloc(sizeof(LINK));
curr->next = NULL;
curr->priority = -1;
(*head)=curr;
}
Functions file
#ifndef PRIORITY_QUEUE_H_
#define PRIORITY_QUEUE_H_
typedef struct priorityQueue{
int priority;
DATA value;
struct priorityQueue *next;
}LINK;
void createEmpty(LINK **head);
void add(LINK **head, int p, DATA v);
void deleteElement(LINK **head, int *p, DATA *v);
void checkIfEmpty(LINK *head);
void destroy(LINK *head);
#endif
Header
I use a project on codeblocks to compile it. Also, "typedef int DATA;" on main would be preferred