Circular Queue by linklist

PHOTO EMBED

Mon Mar 20 2023 13:20:25 GMT+0000 (Coordinated Universal Time)

Saved by @shru_09 #c

#include<stdio.h>
#include<stdlib.h>

struct Node
{
   int data;
   struct Node*next;
};
struct Node *f= NULL;
struct Node *r= NULL;
void enqueue(struct node *top  ,int d) //Insert elements in Queue
{
	struct node* n;
	n = (struct node*)malloc(sizeof(struct node));
	n->data = d;
	n->next = NULL;
	if((r==NULL)&&(f==NULL))
	{
		f = r = n;
		r->next = f;
	}
	else
	{
		r->next = n;
		r = n;
		n->next = f;
	}
} 
void dequeue(struct node * top) // Delete an element from Queue
{
	struct node* t;
	t = f;
	if((f==NULL)&&(r==NULL))
		printf("\nQueue is Empty");
	else if(f == r){
		f = r = NULL;
		free(t);
	}
	else{
		f = f->next;
		r->next = f;
		free(t);
	}
	
	
}
void print(){ // Print the elements of Queue
	struct node* t;
	t = f;
	if((f==NULL)&&(r==NULL))
		printf("\nQueue is Empty");
	else{
		do{
			printf("\n%d",t->data);
			t = t->next;
		}while(t != f);
	}
}

int main(){
	top = enqueue(top,17);
	
return 0;
}
content_copyCOPY