Hello all, I just finished writing this program based on theory (FIRST IN FIRST OUT). Anyway my question is that is the above program considered a queue. The program in the book is very different from what i have written. I compiled it and it runs fine, but i just wanted to know if it is considered a queue.Code:#include<stdio.h> #include<stdlib.h> struct queue { int n; struct queue *next; }; struct queue *q; void push(); void pop(); void show(); int main() { int op; q=NULL; while(1) { printf("MENU OF QUEUE OPTIONS\n"); printf("1.Push\n2.Pop\n3.Show\n4.Exit\n"); printf("CHOOSE AN OPTION!\n"); scanf("%d",&op); switch(op) { case 1: push(); break; case 2: pop(); break; case 3: system("CLS");show(); break; case 4: exit(1); default: printf("NOT A VALID OPTION!\n");break; } } getch(); } void pop() { struct queue *t; t=q; if(t==NULL) { printf("QUEUE IS EMPTY!\n"); return 0; } q=q->next; free(t); t=NULL; } void show() { struct queue *t; t=q; if(t==NULL) { printf("QUEUE IS EMPTY!\n"); return 0; } while(1) { printf("%d\n",t->n); if(t->next==NULL) break; t=t->next; } } void push() { int num; struct queue *t; t=q; printf("ENTER A NUMBER TO PUSH!\n"); scanf("%d",&num); if(t==NULL) { t=(struct queue *)malloc(sizeof(struct queue)); t->n=num; t->next=NULL; q=t; } else { while(1) { if(t->next==NULL) { t->next=(struct queue *)malloc(sizeof(struct queue)); t=t->next; t->n=num; t->next=NULL; break; } t=t->next; } } }
Thank You !



LinkBack URL
About LinkBacks



