logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

C++ Program to Implement Queue in STL

Posted on October 11, 2013 by Manish
This C++ Program demonstrates implementation of Queue in STL.

Here is source code of the C++ Program to demonstrate Queue in STL. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to Implement Queue in Stl
  3.  */
  4. #include <iostream>
  5. #include <queue>
  6. #include <string>
  7. #include <cstdlib>
  8. using namespace std;
  9. int main()
  10. {
  11.     queue<int> q;
  12.     int choice, item;
  13.     while (1)
  14.     {
  15.         cout<<"\n---------------------"<<endl;
  16.         cout<<"Queue Implementation in Stl"<<endl;
  17.         cout<<"\n---------------------"<<endl;
  18.         cout<<"1.Insert Element into the Queue"<<endl;
  19.         cout<<"2.Delete Element from the Queue"<<endl;
  20. 	cout<<"3.Size of the Queue"<<endl;
  21.         cout<<"4.Front Element of the Queue"<<endl;
  22.         cout<<"5.Last Element of the Queue"<<endl;
  23.         cout<<"6.Exit"<<endl;
  24.         cout<<"Enter your Choice: ";
  25.         cin>>choice;
  26.         switch(choice)
  27.         {
  28.         case 1:
  29.             cout<<"Enter value to be inserted: ";
  30.             cin>>item;
  31.             q.push(item);
  32.             break;
  33.         case 2:
  34.             item = q.front();
  35.             q.pop();
  36.             cout<<"Element "<<item<<" Deleted"<<endl;
  37.             break;
  38.         case 3:
  39. 	    cout<<"Size of the Queue: ";
  40. 	    cout<<q.size()<<endl;
  41.             break;
  42.         case 4:
  43.             cout<<"Front Element of the Queue: ";
  44. 	    cout<<q.front()<<endl;
  45.             break;
  46.         case 5:
  47.             cout<<"Back Element of the Queue: ";
  48.             cout<<q.back()<<endl;
  49.             break;
  50.         case 6:
  51.             exit(1);
  52. 	    break;
  53.         default:
  54.             cout<<"Wrong Choice"<<endl;
  55.         }
  56.     }
  57.     return 0;
  58. }

advertisement
$ g++ queue.cpp
$ a.out
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1
Enter value to be inserted: 9
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1 
Enter value to be inserted: 8
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1
Enter value to be inserted: 7
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1
Enter value to be inserted: 6
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1
Enter value to be inserted: 5
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 1
Enter value to be inserted: 4
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 3
Size of the Queue: 6
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 4
Front Element of the Queue: 9
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 5
Back Element of the Queue: 4
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 2
Element 9 Deleted
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 3
Size of the Queue: 5
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 4
Front Element of the Queue: 8
 
---------------------
Queue Implementation in Stl
 
---------------------
1.Insert Element into the Queue
2.Delete Element from the Queue
3.Size of the Queue
4.Front Element of the Queue
5.Last Element of the Queue
6.Exit
Enter your Choice: 6
 
 
------------------
(program exited with code: 1)
Press return to continue

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
« Prev Page - C++ Program to Implement Set_Difference in STL
» Next Page - C++ Program to Implement LeftList Heap

« C++ Program to Implement Network_Flow Problem
C++ Program to Implement LeftList Heap »

Deep Dive @ Sanfoundry:

  1. Java Programming Examples on Collection API
  2. Java Programming Examples on Data-Structures
  3. C Programming Examples on Linked List
  4. C# Programming Examples on Functions
  5. C++ Programming Examples on Data-Structures
  6. C Programming Examples on Searching and Sorting
  7. C Programming Examples on Data-Structures
  8. C++ Programming Examples on STL
  9. C# Programming Examples on Interfaces
  10. C Programming Examples on Stacks & Queues
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.