How to show that the queue is full / queue underflow using linked list , i mean what are the basic steps to make the program to display it ?? can anyone help me to put the "stack is full" option under the insert function in this given program?? i wan't to add only that function !! i tried my best but didn't find any proper solution ! any help would mean a lot to me !! program is given below , i just wan't to add the "queue is full" option !! thanx a lot in advance program !! View attachment queue.txt
Queue full and queue underflow are two different conditions and you cannot check for them both at the same time (well, you could, but there's not a lot of point. There's no need to check if the queue is about to underflow when you add an item, or if the queue is about to overflow when you delete an item). Linked lists generally only need to run out when memory runs out so a queue full should normally correspond to a check for failure to allocate memory, but the error then should be "not enough memory", not "queue full". However there could be design reasons for your queue being limited in size (but then, why are you using a linked list instead of a simple array?). Anyway, it's not difficult. Just check if the queue is at maximum size and throw an error when the user tries to add more: Code: void insert(item *i) { if (queue_size < max_size) { // .. as per your existing code, and don't forget of course: queue_size++; } else { printf("Queue is full\n"); } } Queue underflow is very similar, except I'm going to make you guess what the comparison should be: Code: void remove(item *i) { if (/* what goes here? */) { // .. as per your existing code, again not forgetting: queue_size--; } else { printf("Queue underflow\n"); } } If you can't guess, think about it for a bit. What are the range of possible values queue_size could have if the queue is about to underflow?