GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

Implement Queue in Python

Gk Scientist November 29, 2022 No Comments
Tweet WhatsApp Telegram

Queue in Python:

We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.

(1) Queue is an ordered linear list of elements, having different ends for adding and removing elements in it. It works on First-In-First-Out (FIFO) principle, meaning an element that comes in first goes out first when a value is read from a queue. A queue has two main operations called enqueue and dequeue. Enqueue is used to insert a new element to the queue at the rear end. Dequeue is used to remove one element at a time from the front of the queue.

(2) Example of Implementation of Queue in Python:

queue in python - Implement Queue in Python

Now run the code, and you got the following output as shown below.

python queue - Implement Queue in Python

Now press 1 in the output window, in order to use the Push operation. After pressing 1, you got the message “enter any value”. You add any value of your choice. If you want to add another value then again click on 1 and you got the same message “enter any value”. You can add as many values as you want. The output is shown below.

push operation in queue 351x1024 - Implement Queue in Python

Now the list is created by using the push operation. Now press 2 in the output window, in order to use the Pop operation. After pressing 2, ‘20’ will be dropped from the list as shown below.

pop operation on queue in python - Implement Queue in Python

After pressing 3 we get the first element of the list as shown below.

front operation in queue in python - Implement Queue in Python

After pressing 4 we get the last element of the list as shown below.

last element operation in python - Implement Queue in Python

Now press 5 in the output window, in order to use the Display operation. This operation displays the full queue as shown below. You got only three values in the list because you have dropped the first value already by using the pop operation.

display operation in queue in python - Implement Queue in Python

If you press 6, the process is getting finished.

Note: In the above example, we have performed a step-by-step operation. If you press 2 before 1, then the pop operation comes into play and you got the message “Empty Queue” as we set in the code as shown above because you did not create the list, so there will be no data that is why you got the output “Empty Queue”. The same is apply to all conditions.


Implement Stack in Python
MySQL Left Join and Right Join
MySQL Primary Key and Foreign Key
MySQL Aggregate Functions
Procedure-Oriented Programming
Object-Oriented Programming (OOP)
World Wide Web (WWW)
Python (programming language)– Wikipedia
Prev Article
Next Article

Related Articles

Create JSON File in Python
Create JSON File in Python: We can use the PyCharm …
Gk Scientist December 4, 2022 Computer

Create JSON File in Python

Python Function Overloading and Overriding
Python Function Overloading and Overriding: We can use the PyCharm …
Gk Scientist December 6, 2022 Computer

Python Function Overloading and Overriding

C++ Data Types
C++ Data Types: A data type is a term that …
Gk Scientist September 18, 2022 Computer

C++ Data Types

Relational Operators in Java
Relational Operators in Java: We can use the Eclipse IDE …
Gk Scientist January 1, 2023 Computer

Relational Operators in Java

MySQL UPDATE Statement
MySQL UPDATE Statement: The primary statement used to modify the …
Gk Scientist November 15, 2022 Computer

MySQL UPDATE Statement

How to Create Variables in Python
Create Variables in Python: We can use the PyCharm code …
Gk Scientist November 21, 2022 Computer

How to Create Variables in Python

Java Switch Statement
Java Switch Statement: We can use the Eclipse IDE for …
Gk Scientist January 1, 2023 Computer

Java Switch Statement

Python Data Types
Python Data Types: We can use the PyCharm code editor …
Gk Scientist November 23, 2022 Computer

Python Data Types

Leave a Reply Cancel Reply

Search

  • Popular
  • Recent

GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (34) Biology Questions (89) Chemistry (57) Computer (215) Current Affairs (4) Current Content (0) Economy (18) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (115) Physics (89) Political Science (134) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
 

Loading Comments...