A queue is a data structure that follows the first-in, first-out (FIFO) principle. Elements are added to the rear of the queue and removed from the front. A queue can be implemented using an array, with indexes to track the front and rear elements. When an element is added (enqueued), the rear index is incremented; when an element is removed (dequeued), the front index is incremented and the element at that index is returned. The queue has a limited capacity based on the size of the array.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Queue in C, Queue Real Life of ExampleHitesh Kumar
Queue in C : Working of queue on the basis of first-in-first-out (FIFO) data structure.
Queue Real Life of Example
https://www.sitesbay.com/cpp-datastructure/cpp-queue-program-example
Ticket Counter : First person get ticket first and go out first.
Stack and Queue.pptx university exam preparationRAtna29
Queues and stacks are dynamic while arrays are static. So when we require dynamic memory we use queue or stack over arrays. Stacks and queues are used over arrays when sequential access is required. To efficiently remove any data from the start (queue) or the end (stack) of a data structure
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
Venay Magen likes the shading red, particularly on Tuesdays. He cherishes to drink bourbon (on all days). He figured out how to drink whisky from his youth companion Zippo, when they went to class together at Mount Temple Comprehensive School. He is best known as the lead vocalist for the band MN3.
Discover the wonders of the Wenatchee River with a variety of river tours in Monitor, WA. Whether you're seeking thrilling whitewater rafting, peaceful kayaking, family-friendly float trips, or scenic sunset cruises, there's something for everyone. Enjoy fishing, wildlife spotting, bird watching, and more in this beautiful natural setting, perfect for outdoor enthusiasts and families alike.
The Power of a Glamping Go-To-Market Accelerator Plan.pptxRezStream
Unlock the secrets to success with our comprehensive 8-Step Glamping Accelerator Go-To-Market Plan! Watch our FREE webinar, where you'll receive expert guidance and invaluable insights on every aspect of launching and growing your glamping business.
Our Ooty honeymoon package from Chennai is a perfect escape for newlywed couples to celebrate their love and start their new life together. Our package offers a range of itineraries to cater to the diverse preferences of couples. From adventure activities to relaxing spa sessions, these packages are designed to provide the perfect balance between adventure and relaxation.
How To Talk To a Live Person at American Airlinesflyn goo
This page by FlynGoo can become your ultimate guide to connecting with a live person at American Airlines. Have you ever felt lost in the automated maze of customer service menus? FlynGoo is here to rescue you from endless phone trees and automated responses. With just a click or a call to a specific number, we ensure you get the human touch you deserve. No more frustration, no more waiting on hold - we simplify the process, making your travel experience smoother and more enjoyable.
Discover Palmer, Puerto Rico, through an immersive cultural tour that unveils its rich history and vibrant traditions. Experience lively festivals, savor authentic cuisine, and explore local markets. Visit historical landmarks, museums, and stunning colonial architecture. Engage with friendly locals, enjoy live music, and hike scenic nature trails, all while participating in cultural workshops and discovering unique artisan crafts.
LUXURY TRAVEL THE ULTIMATE TOKYO EXPERIENCE FROM SINGAPORE.pdfDiper Tour
Get off on the most luxurious Tokyo itinerary from Singapore. Experience Tokyo’s sophisticated modernism and rich tradition with first-class travel, sumptuous lodging, fine food, and special tours. Savor the finest that this energetic city has to offer for an experience that will never be forgotten.
4 DAYS MASAI MARA WILDEBEEST MIGRATION SAFARI TOUR PACKAGE KENYABush Troop Safari
Join our 4-day Masai Mara Wildebeest Migration Safari in Kenya. Witness the incredible wildebeest migration, enjoy exciting game drives, and stay in comfortable lodges. Get up close and personal with one of nature's most amazing exhibits! Book Your Safari Today at - https://bushtroop-safaris.com/
London Country Tours, the foremost travel partner offers customized Stonehenge tours from London coming with private tour guides and direct access to the inner circles. Visit: https://www.londoncountrytours.co.uk/tour/tours-to-stonehenge-oxford/
How To Change Name On Volaris Ticket.pdfnamechange763
How to change name on Volaris ticket? This is one of the most common questions asked by travelers flying with Volaris Airlines. The mentioned details can help you with your name rectification on the airline ticket. If you are still facing difficulties call the consolidation desk at +1-800-865-1848.
During the coldest months, Italy transforms into a winter wonderland, providing visitors with a very unique experience. From the Settimana Bianca ski event to the lively Carnevale celebrations, Italy's winter festivities provide something for everyone. Enjoy hot cocoa, eat hearty comfort foods, and buy during winter deals. Explore the country's rich cultural past by participating in Settimana Bianca, and Carnevale, sipping hot chocolate, shopping during winter deals, and indulging in winter comfort foods. Visit our website https://timeforsicily.com/ for more information.
Its running cost is among the diverse vital aspects you must consider before buying an electric scooter. Calculate the cost of getting e-scooter charge for your regular usage to calculate its economic efficiency, similar to people who investigate the mileage of petrol or diesel-driven scooters.
Antarctica- Icy wilderness of extremes and wondertahreemzahra82
In this presentation, we delve into the captivating realm of Antarctica, Earth's southernmost continent. This icy wilderness stands as a testament to extremes, with record-breaking cold temperatures and vast expanses of pristine ice. Antarctica's landscape is dominated by towering glaciers, colossal icebergs, and expansive ice shelves. Yet, amidst this frozen expanse, a rich tapestry of unique wildlife thrives, including penguins, seals, and seabirds, all finely attuned to survive in this harsh environment. Beyond its natural wonders, Antarctica also serves as a vital hub for scientific exploration, providing invaluable insights into climate change and the Earth's history
Exploring Montreal's Artistic Heritage Top Art Galleries and Museums to VisitSpade & Palacio Tours
Montreal boasts a vibrant artistic heritage, showcased in its top art galleries and museums. From the expansive collections at the Montreal Museum of Fine Arts to the cutting-edge exhibits at the Musée d'art contemporain, discover the city's rich cultural landscape. Experience dynamic street art, indigenous works, and contemporary pieces, reflecting Montreal's diverse and innovative art scene.
BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. Get information in this PDF and simplyfy your visa process.
2. What is a stack?
Stores a set of elements in a particular order
Stack principle: LAST IN FIRST OUT
= LIFO
It means: the last element inserted is the first one to
be removed
Example
Which is the first element to pick up?
3. Last In First Out
top
top E
D D D
C top C C C
B top B B B B
A A A A A
A top
4. Stack Applications
Real life
Pile of books, files, plates
TOH
More applications related to computer science
stack Program execution
Evaluating expressions
Palindrome finder
Parentheses matcher
A Palindrome is a string that reads the same in
either direction
Examples: “Able was I ere I saw Elba”
5. Stack
objects: a finite ordered list with zero or more elements.
methods:
Stack createS(max_stack_size) ::=
create an empty stack whose maximum size is
max_stack_size
Boolean isFull(stack, max_stack_size) ::=
if (number of elements in stack == max_stack_size)
return TRUE
else return FALSE
Stack push(stack, item) ::=
if (IsFull(stack)) stack_full
else insert item into top of stack and return
6. Stack (cont’d)
Boolean isEmpty(stack) ::=
if(stack == CreateS(max_stack_size))
return TRUE
else return FALSE
Element pop(stack) ::=
if(IsEmpty(stack)) return
else remove and return the item on the
top of the stack.
7. Array-based Stack Implementation
Allocate an array of some size (pre-defined)
Maximum N elements in stack
Bottom stack element stored at element 0
last index in the array is the top
Increment top when one element is pushed,
decrement after pop
8. Stack Implementation
#include <stdio.h>
#include<conio.h>
# define MAXSIZE 200
int stack[MAXSIZE];
int top; //index pointing to the top of stack
void main()
{
void push(int);
int pop();
int will=1,i,num;
clrscr();
while(will ==1)
{
printf(" MAIN MENU:n 1.Add element to stackn2.Delete element from the stack");
scanf("%d",&will);
8 Chapter 5: Stacks
9. switch(will)
{
case 1:
printf("Enter the data... ");
scanf("%d",&num);
push(num);
break;
case 2: i=pop();
printf("Value returned from pop function is %d ",i);
break;
default: printf("Invalid Choice . ");
}
printf(" Do you want to do more operations on Stack ( 1 for yes, any
other key to exit) ");
scanf("%d" , &will);
} //end of outer while
} //end of main
9 Chapter 5: Stacks
12. The Towers of Hanoi
A Stack-based Application
GIVEN: three poles
a set of discs on the first pole, discs of different sizes, the
smallest discs at the top
GOAL: move all the discs from the left pole to the right one.
CONDITIONS: only one disc may be moved at a time.
A disc can be placed either on an empty pole or on top of a
larger disc.
22. STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
Reverse polish notation :is a postfix notation
(places operators after operands)
(Example)
Infix notation A+B
Reverse Polish notation AB+ also called
postfix.
23. STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
A stack organization is very effective for evaluating
arithmetic expressions
A*B+C*D (AB *)+(CD *) AB * CD * +
(3*4)+(5*6) 34 * 56 * +
24. STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
n • Evaluation procedure:
n 1. Scan the expression from left to right.
2. When an operator is reached, perform the operation with the two
operands found on the left side of the operator.
3. Replace the two operands and the operator by the result obtained
from the operation.
n (Example)
infix 3 * 4 + 5 * 6 = 42
postfix 3 4 * 5 6 * +
n 12 5 6 * +
12 30 +
42
25. STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
• Reverse Polish notation evaluation with a stack.
Stack is the most efficient way for evaluating arithmetic
expressions.
stack evaluation:
Get value
If value is data: push data
Else if value is operation: pop, pop
evaluate and push.
28. The Queue Operations
A queue is like a line
of people waiting for a
bank teller. The queue
has a front and a
rear. $ $
Front
Rear
29. The Queue Operations
New people must enter the queue at
the rear. The C++ queue class calls
this a push, although it is usually
called an enqueue operation.
$ $
Front
Rear
30. The Queue Operations
When an item is taken from the queue,
it always comes from the front. The
C++ queue calls this a pop, although it
is usually called a dequeue operation.
$ $
Front
Rear
31. The Queue Class
The C++ template <class Item>
standard class queue<Item>
template library {
has a queue public:
template class. queue( );
void push(const Item&
The template
entry);
parameter is the void pop( );
type of the items bool empty( ) const;
that can be put in Item front( ) const;
the queue. …
32. Array Implementation
A queue can be implemented with an array, as
shown here. For example, this queue contains
the integers 4 (at the front), 8 and 6 (at the rear).
[0] [1] [2] [3] [4] [5] ...
4 8 6
An array of
integers to
implement a We don't care what's in
queue of integers this part of the array.
33. Array Implementation
The easiest implementation also 3 size
keeps track of the number of items in
the queue and the index of the first first
0
element (at the front of the queue),
the last element (at the rear).
2 last
[0] [1] [2] [3] [4] [5] ...
4 8 6
34. A Dequeue Operation
When an element leaves the queue, 2 size
size is decremented, and first
changes, too. first
1
2 last
[0] [1] [2] [3] [4] [5] ...
4 8 6
35. An Enqueue Operation
When an element enters the queue, 3 size
size is incremented, and last
changes, too. first
1
3 last
[0] [1] [2] [3] [4] [5] ...
8 6 2
36. At the End of the Array
There is special behavior at the end 3 size
of the array. For example, suppose
we want to add a new element to this first
3
queue, where the last index is [5]:
5 last
[0] [1] [2] [3] [4] [5]
2 6 1
37. At the End of the Array
The new element goes at the front of 4 size
the array (if that spot isn’t already
used): first
3
0 last
[0] [1] [2] [3] [4] [5]
4 2 6 1
38. Array Implementation
Easy to implement 3 size
But it has a limited capacity with a fixed array
Or you must use a dynamic array for an 0 first
unbounded capacity
Special behavior is needed when the rear
2 last
reaches the end of the array.
[0] [1] [2] [3] [4] [5] ...
4 8 6
39. Linked List Implementation
A queue can also be
implemented with a linked list
with both a head and a tail 13
pointer.
15
10
7
null
head_ptr
tail_ptr
40. Linked List Implementation
Which end do you think is the
front of the queue? Why?
13
15
10
7
null
head_ptr
tail_ptr
41. Linked List Implementation
The head_ptr points to the
front of the list.
Because it is harder to remove Front
13
items from the tail of the list.
15
10
7
null
head_ptr
tail_ptr
Rear
42. A priority queue is a container in which
access or deletion is of the highest-
priority item, according to some way of
Assigning priorities to items.
42 Priority Queues
43. FOR EXAMPLE, SUPPOSE A HOSPITAL
EMERGENCY ROOM HAS THE
FOLLOWING FOUR PATIENTS, WITH
NAME, PRIORITY, AND INJURY:
43 Priority Queues
44. Matt 20 sprained ankle
Andrew 45 broken leg
Samira 20 high blood pressure
Kerem 83 heart attack
IN WHAT ORDER SHOULD THE
PATIENTS BE TREATED?
44 Priority Queues
45. THERE ARE MANY APPLICATIONS
OF PRIORITY QUEUES, IN AREAS AS
DIVERSE AS SCHEDULING, DATA
COMPRESSION, AND JPEG (Joint
Photographic Experts Group) ENCODING.
45 Priority Queues
46. Using Priority Queue to
Track Your Assignments
Organize class or work assignments by due dates
Early due date, higher priority
diagram of class Assignment