I am currently working on my homework. In my program I had to use queue, so I wrote a queue with Linked list. But it doesn't seem to like my syntax.
So I have struct
typedef struct Node{
pthread_t thread;
int threadID;
int securityMode; // nTS = 1, S = 2, U = 3
//int cluseterHalf; //either 1st or 2nd
struct NODE *next;
int executionTime;
int isLast;
}NODE;
typedef NODE *Link;
And this is where I tried to do Enqueue.
void Enqueue(Link node, Link *Queue){
Link previous = NULL;
Link current = *Queue;
while (current->isLast){
previous = current;
current = current->next;
}
if(previous == NULL){
node->next = current;
*Queue = node;
}
else{
previous->next = node;
node->next = current;
}
}
I tried to change my code a bit, but I am getting this error.
Cluster.c:162:13: warning: assignment from incompatible pointer type
[enabled by default]
current = current->next;
^
Cluster.c:165:16: warning: assignment from incompatible pointer type [enabled by default]
node->next = current;
^
Cluster.c:169:20: warning: assignment from incompatible pointer type [enabled by default]
previous->next = node;
^
Cluster.c:170:16: warning: assignment from incompatible pointer type [enabled by default]
node->next = current;
I have tried to look at some stackoverflow questions similar to mine. 1)Question1
So I made many logical and non-logical attempts. I tried to write node->next = ¤t since next is a pointer and it will get the address value. But it didn't work :( I also tried to do oposit *(node->next) = current
I finally found the correct option for me, but I am not sure If that's what I wanted. I was thinking that I had to have struct NODE *next but If I change NODE *next to NODE next than I don't get those errors. But I get different one:
Cluster.c:25:15: error: field ‘next’ has incomplete type
struct NODE next;
Can you please tell me how to fix this problem? Thanks!