EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Queue in C

Home » Software Development » Software Development Tutorials » C Programming Tutorial » Queue in C

Queue in C

Introduction to Queue in C

Queue in C is a data structure that is not like stack and one can relate the behavior of queue in real -life. Unlike stack which is opened from one end and closed at the other end which means one can enter the elements from one end only. Therefore, to overcome the scenario where we need to insert elements from both ends is needed and this flexibility is being provided by the data structure Queue in C. These data structures play a very pivotal role in our day to day life in a way that efficiency and implementation become more flexible and versatile.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Basically, there is no specific syntax for Queue its just that we have certain operations to perform on queue as it works on FIFO order [First In First Out]. This data structure like the stack is used for the removal of items in the FIFO order itself.

Common Syntax will include all these operations to be performed with data structures which are as follows:

  • Enqueue()
  • Dequeue()
  • Front()
  • Rear()

Struct Queue {
// will create a queue
// allocation of memory to the queue
// empty queue or full queue
// Perform function with the operations such as enqueue, dequeue, Front and Rear ()
}

How does queue work in C?

As mentioned above Queue already has these operations to be performed but on the other hand, it has some more operations to be performed simultaneously that will imply whether or not we need the desired element to be inserted or deleted and whether the queue has the capacity to insert or delete which means whether it is overflow or underflow situation.

One classic example of the queue which we can relate to the real-world scenario is people standing in the queue of a ticket counter. One person comes and joins the queue whereas other people who is collecting the ticket once collects gets out of the queue. Exactly this way a queue functions in FIFO order. The person who is coming first will be served first.

Popular Course in this category
C Programming Training (3 Courses, 5 Project)3 Online Courses | 5 Hands-on Projects | 34+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,570 ratings)
Course Price

View Course

Related Courses
C++ Training (4 Courses, 5 Projects, 4 Quizzes)Java Training (40 Courses, 29 Projects, 4 Quizzes)

A Queue can be implemented in many ways using arrays, linked lists, Pointers and Structures. But for some simplicity’s sake, we should implement it using the single-dimensional or one-dimensional array.

Before going into detail, we should have prior knowledge of when to use the current data structure and Why to use it?

The queue never gets used if we are in a need of quick and urgent processing of a set of input and output. Processing using queue takes place using FIFO and especially while using Breadth-First Search. This provides and lets queue to become a versatile and flexible data structure.

Scenarios can be as follows:

  • When multiple consumers make use of or in need of a single resource makes use of queue as a data structure. Example: Disk Scheduling, CPU Scheduling.
  • When data sent and received is not at the same pace or rate while transfer from one pipe to another or node to another or files and Buffers.

Now, therefore, we land in a situation of using queue and now we will go through the proper working:

For implementing queue, we need to get two pointers which will continuously keep a track on both the ends and will get incremented when we need to enqueue an element from the front and when we need to dequeue an item from the rear end again depends on the requirement.

Even if we continuously keep on moving a pointer and let it increment then also a problem will come where the front pointer may reach to the end or cross the rear end. Therefore, to avoid this problem it is needed to move both the pointer in a circular manner.

Queue Member Types in C

There are three types namely:

  • Priority Queue
  • Circular Queue
  • Deque

1. Priority Queue

As its name suggests a priority queue is a kind of queue that will be assigned a priority to the elements needed to be inserted or deleted.

Assignment of rules are as follows:

  • An element inserted with higher priority will be processed first and then with the lower priority.
  • Two elements being added simultaneously will get the priority in an order in which they are added simultaneously.

Further this priority queue can be divided into two types depending on the scenario:

  • Ascending Priority Queue
  • Descending Priority Queue

All time-sharing systems make use of the Ascending or descending priority queue depending upon the scenarios.

2. Circular Queue

Circular Queue Is a kind of queue which Is used to select the item from the queue which is the very first index or a location inserted within the queue till the last location when the queue is full. Any new element will be inserted if and only if the last location is empty.

Rules following that are:

  • When the front is pointing to the first element.
  • If front=rear and then the queue becomes empty.
  • Whenever a new element is inserted an increment is made to the rear end saying one rear[index] gets incremented by rear+1.

3. Deque

Deque stands for the double-ended queue which will be let the elements get entered in both ways that is the front end and rear end both.

Further, these are of two types:

  • Input Restricted Dequeues.
  • Output Restricted Dequeues.

Queue Functions in C

Basic Functions involves:

1. Enqueue(): This function will help in the insertion of elements from either of the ends whether front end or rear end.

2. Dequeue(): This function will help in the deletion of elements from either of the ends whether front end or rear end.

3. Peek(): It will help in getting the element in front of the queue without eliminating it from the pipe.

4. isFull(): This function will ensure that the queue is full, and no more element can be inserted as it is in overflowing condition.

5. isEmpty(): This function will help to determine whether the queue is empty I.e. in underflow condition.

Conclusion

Queue in C is a versatile and data structure in C which overcomes the problems of insertion and deletion of elements whether from the front end or rear end. Moreover, it has the capability of determining the operations in a way that they can be enqueued and dequeued in any way. Unlike stack, it is being used in First in First Out [FIFO] order.

Recommended Articles

This is a guide to Queue in C. Here we discuss How queue works in C along with the three types of members and basic functions. You may also have a look at the following articles to learn more –

  1. Queue in C#
  2. Queue in C++
  3. Queue in Java
  4. C++ Queue

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
C Programming Tutorial
  • Advanced
    • Constructor in C
    • Encapsulation in C
    • C Storage Classes
    • Static Keyword in C
    • File Handling in C
    • Queue in C
    • Hexadecimal in C 
    • typedef in C
    • Memory Allocation in C
    • Linked List in C
    • Volatile in C
    • Tokens in C
    • Expression in C
    • Regular Expression in C
    • Error Handling in C
    • Types of Errors in C
    • Preprocessor in C
    • Preprocessor Directives in C
    • fscanf() in C
    • #Pragma in C
    • #ifndef in C
    • #undef in C
    • Macros in C
  • Basic
    • Introduction to C
    • What is C
    • Career in C Programming
    • Advantages of C
    • How to Install C
    • Best C Compilers
    • Data Types in C
    • Variables in C
    • C Keywords
    • C Command
    • Command Line Arguments in C
    • C Literals
    • Constants in C
    • Unsigned Int in C
    • String in C
  • Pointers
    • Pointers in C
    • Null pointer in C
    • Function Pointer in C
    • Double Pointer in C
    • Void Pointer in C
    • Const Pointer in C
    • Dangling Pointers in C
    • Pointer Arithmetic in C
  • Operators
    • C Operators
    • Arithmetic Operators in C
    • Relational Operators in C
    • Assignment Operators in C
    • Logical Operators in C
    • Conditional Operator in C
    • Modulus Operator in C
    • Ternary Operator in C
    • Address Operator in C
    • Unary Operator in C
    • Operators Precedence in C
    • Left Shift Operator in C
  • Control Statement
    • Control Statements in C
    • If Statement in C
    • If-else Statement in C
    • Else if Statement in C
    • Nested if Statement in C
    • #else in C
    • Structure Padding in C
    • Nested Structure in C
    • Continue Statement in C
    • Break Statement in C
    • Switch Statement in C
    • Goto Statement in C
  • Loops
    • Loops in C
    • For Loop in C
    • While Loop in C
    • Do While Loop in C
    • Nested Loop in C
    • Infinite Loop in C 
  • Function
    • Math Functions in C
    • Hashing Function in C
    • Recursive Function in C
    • Power Function in C
    • fputs in C
    • C puts() Function
    • fprintf() in C
    • fseek() in C
    • Stderr in C
    • ASCII Value in C
    • strcat() in C
    • Inline Function in C
    • sizeof() in C
    • Function Prototype in C
    • C ftell()
  • Array
    • Arrays in C Programming
    • 2-D Arrays in C
    • 3D Arrays in C
    • Multidimensional Array in C
    • Array Functions in C
    • Strings Array in C
  • Sorting
    • Sorting in C
    • Heap Sort in C
  • C programs
    • Patterns in C Programming
    • Star Patterns in C
    • Number Patterns in C
    • Swapping in C
    • Reverse Number in C
    • Palindrome in C Program
    • Factorial in C
    • Fibonacci Series in C
    • Square Root in C
    • Random Number Generator in C
    • Prime Numbers in C
    • Escape Sequence in C
    • Reverse String in C
    • Leap Year Program in C
    • Anagram Program in C
    • Strong Number in C
    • String Concatenation in C
    • C Programming Matrix Multiplication
    • Decimal to Octal in C
    • Expression Evaluation in C
    • Decimal to Hexadecimal in C
  • Interview question
    • C Programming Interview Questions

Related Courses

C Programming Training Course

C++ Training Course

Java Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C Programming Training Course Learn More