So I'm having this error:
.\linkedbank.c: In function 'enqueue':
.\linkedbank.c:48:17: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
q->rear->next = temp;
Which is weird, because im sure temp is the same exact type as q->rear->next. Am I missing something? this is the code:
#include <stdio.h>
#include <stdlib.h>
//=============STRUCTS=============//
typedef struct{
int data;
struct node* next;
}node;
typedef struct{
node* front;
node* rear;
}queue;
//============PRIMITIVE FUNCS======//
void enqueue(queue* q, int x);
int dequeue(queue* q);
//====Utility Funcs//
queue* createQueue();
void destroyQueue();
int isEmpty(queue* q); //Cannot get full! and O(1) runtime!!!
void displayQueue(queue* q);
//============ FUNCTION DEFINITIONS =====//
void enqueue(queue* q, int x)
{
node* temp = (node*)malloc(sizeof(node));
temp->data = x;
temp->next = NULL;
if(isEmpty(q))
{
q->front = q->rear = temp;
}else
{
q->rear->next = temp;
q->rear = temp;
}
}
int dequeue(queue* q)
{
node* temp = q->front;
if(isEmpty(q))
{
fprintf(stderr, "CANNOT DEQUEUE EMPTY QUEUE");
return -1;
}else if(q->front == q->rear)
{
q->front = q->rear = NULL;
}else
{
q->front = q->front->next;
}
return temp->data;
free(temp);
}
int isEmpty(queue* q){
return (q->front->next == NULL && q->rear->next == NULL);
}
So as you can see q->rear and q->front are both (node*), and temp is also (node*) how are these incompatible if they're the same type? Im so confused, please help.