Queue implementation program in C -
Queue implementation program in C -
ive started c , i'm trying queue implementation programme book isn't working. giving error function qfull , qempty undefined. after declaring function still giving more errors.
#include <stdio.h> #include <process.h> #include <conio.h> #define queue_size 5 void main() { void insert_rear(int, int *, int *); void delete_front(int *, int *, int *); void display(int *, int, int); int choice, item, f, r, q[10]; /* queue empty */ f = 0; /* front end end of queue*/ r = -1; /* rear end of queue*/ (;;) { clrscr(); printf("\t\t\t ordinary queue operation\n\n"); printf("\t\t\t 1 …. force / insert\n"); printf("\t\t\t 2 …. pop / delete\n"); printf("\t\t\t 3 …. view / display\n"); printf("\t\t\t 4 …. exit\n\n\n"); printf("\t\t\t come in selection : "); scanf("%d", &choice); switch (choice) { case 1: // force queue printf("enter item inserted : "); scanf("%d", &item); insert_rear(item, q, &r); continue; case 2: // pop queue delete_front(q, &f, &r); break; case 3: // display queue display(q, f, r); break; case 4: exit(0); default: printf("\t\t\tinvalid input – seek again"); } // end of switch getch(); }// end of } // end of main /*******************/ void insert_rear(int item, int q[], int *r) { if (qfull(*r)) /* queue total ? */ { printf("\t\t\tqueue overflow\n"); return; } /* queue not total */ q[++(*r)] = item; /* update rear pointer , insert item */ } /*—————————————————————– */ void delete_front(int q[], int *f, int *r) { if (qempty(*f, *r)) { printf("\t\t\tqueue underflow\n"); return; } printf(" pop successfull, element deleted = %d ",q[(*f)++]); if(*f> *r) { *f=0,*r=-1; } } /*********************************************************/ void display(int q[], int f, int r) { int i; if (qempty(f,r)) { printf("queue empty\n"); return; } printf("\t\t\t queue container\n\n"); for(i=f;i<=r; i++) printf("\t\t\t| %5d |\n",q[i]); } /**********************************************/ int qempty(int f, int r) { homecoming (f>r)?1:0; /* returns true if queue empty otherwise returns false */ } /**********************************************/ int qfull(int r) { /* returns true if queue total otherwise false */ homecoming (r==queue_size-1)?1:0; }
you should set these declarations:
void insert_rear(int, int *, int *); void delete_front(int *, int *, int *); void display(int *, int, int);
outside of main (and above it). need declare qfull , and qempty these declarations. if function isn't defined in file above called, has declared above has been called. otherwise, compiler can't 'see' them.
c queue implementation
Comments
Post a Comment