#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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter