0

I am currently trying to implement a queue data structure using a linked list of structs. Currently, I have a node struct for the linked list:

struct Node { int data; struct Node *next; };

and I also have an insert, delete, and display functions to change/access the queue. Here are their signatures:

void insert(int, struct Node*, struct Node*);
void delete(struct Node*);
void display(struct Node*);

I am having trouble with reflecting changes made by those functions to the queue. in my main function, I declare two Node pointers as such:

struct Node *front = NULL;
struct Node *rear = NULL;

which I am using to keep track of the front and rear nodes in the queue. I passed them into the functions as can be seen above. When doing all that, it seems that the front pointer never gets updated, and stays NULL even after my functions are called, so display and delete never really work, and insert does not reflect additions made.

However, when I declare my struct as such:

struct Node { int data; struct Node *next; } *front = NULL, *rear = NULL;

and I don't pass in any arguments that are Node*, it all works fine. Why is that?

EDIT: I don't think I specified, but I am trying to NOT use the second version of my struct; I don't want the front/rear Node pointers declared globally (I think that is what it is called).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
AnJuMak
  • 1
  • 2

0 Answers0