SlideShare une entreprise Scribd logo
1  sur  10
DATA STRUCTURES AND ALGORITHMS
LAB 4

Bianca Tesila
FILS, March 2014
OBJECTIVES
Queue
 Queue vs stack
 Applications

QUEUES


instance of an abstract data type (ADT) that
formalizes the concept of restricted collection
(FIFO = first in first out)
QUEUES: BASIC OPERATIONS


enqueue(x)




dequeue()





Removes the element from the head of the queue and
returns it
Returns an error if the stack is empty

peek()




Adds the element x at the tail of the queue

Returns (but does not remove) the element at the head of
the queue

isEmpty()


Returns 1 if the queue is empty and 0 otherwise
QUEUES: IMPLEMENTATION





with a static data structure (array, circular
array)
with a dynamic data structure (list)

‼Short reminder:
Why do we use circular arrays instead of simple arrays?
QUEUES: WITH SIMPLE ARRAYS
QUEUES: WITH CIRCULAR ARRAYS
QUEUES VS STACKS
‼Exercise:

Implement a stack using 2 queues. The corresponding class is
QueuedStack and has the following methods:
 an empty constructor
 destructor
 push
 pop
There are several solutions for this task.

Using a similar approach, implement a queue using 2 stacks:
StackedQueue.
QUEUES AND STACKS: APPLICATIONS
‼Exercise:
Implement a stack which provides an efficient get minimum
function along with regular push and pop functionality.
Hint: use an auxiliary stack.

Taking into consideration that a queue can be implemented
using 2 stacks, use a similar approach for getting the
minimum element out of a queue.
HOMEWORK
o

Finish all the lab exercises.

o

Implement a messaging system using queues.



Messages are received in the order they are sent
You should use the following classes:










Message
MessageSender
MessageReceiver

A Message object has a sender, recipient, content (make an array
of chars!!) and a date
A Message is placed in a queue by a MessageSender object
A Message is removed from a queue by a MessageReceiver object,
which can also display the content of the message.
Your queue class can receive any types of objects, including
Message Objects

Contenu connexe

Tendances

Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJamsher bhanbhro
 
القوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاالقوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاMahmoud Alfarra
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Python advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmPython advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmJohn(Qiang) Zhang
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
Collections generic
Collections genericCollections generic
Collections genericsandhish
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queuesurya pandian
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Abbott
 
Path compression
Path compressionPath compression
Path compressionDEEPIKA T
 
Python advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresPython advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresJohn(Qiang) Zhang
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in JavaMahmoud Alfarra
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSAjunnubabu
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1SSE_AndyLi
 

Tendances (20)

Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime Functions
 
Python session 10
Python session 10Python session 10
Python session 10
 
القوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاالقوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافا
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Python advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmPython advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithm
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
Collections generic
Collections genericCollections generic
Collections generic
 
Java - Collections
Java - CollectionsJava - Collections
Java - Collections
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
3 Array operations
3   Array operations3   Array operations
3 Array operations
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)
 
Path compression
Path compressionPath compression
Path compression
 
Python advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresPython advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structures
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in Java
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 

En vedette

Conditioned Air Resume
Conditioned Air ResumeConditioned Air Resume
Conditioned Air ResumeTheo Etzel
 
JustinBrooks_NCUR2016_UofMemphis_Presentation
JustinBrooks_NCUR2016_UofMemphis_PresentationJustinBrooks_NCUR2016_UofMemphis_Presentation
JustinBrooks_NCUR2016_UofMemphis_PresentationJustin Brooks
 
Structural Trauma and Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma and Toxic Stress: Lifecourse Roots of Health InequitiesStructural Trauma and Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma and Toxic Stress: Lifecourse Roots of Health InequitiesTomas J. Aragon
 
Sme spokane event summaries
Sme spokane event summariesSme spokane event summaries
Sme spokane event summariesDave Davidson
 
Copy Of Po# 4286215
Copy Of Po# 4286215Copy Of Po# 4286215
Copy Of Po# 4286215guest9522f4
 
dillard's 2008proxystatement
dillard's 2008proxystatementdillard's 2008proxystatement
dillard's 2008proxystatementfinance31
 
Structural Trauma & Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma & Toxic Stress: Lifecourse Roots of Health InequitiesStructural Trauma & Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma & Toxic Stress: Lifecourse Roots of Health InequitiesTomas J. Aragon
 
dillard's annual reports 2007
dillard's annual reports 2007dillard's annual reports 2007
dillard's annual reports 2007finance31
 
dillard's annual reports 2005
dillard's annual reports 2005dillard's annual reports 2005
dillard's annual reports 2005finance31
 
dillard's annual reports 2006
dillard's annual reports 2006dillard's annual reports 2006
dillard's annual reports 2006finance31
 
dillard's annual reports 2004
dillard's annual reports 2004dillard's annual reports 2004
dillard's annual reports 2004finance31
 
10 keys to evaluating DCAA compliant accounting software
10 keys to evaluating DCAA compliant accounting software10 keys to evaluating DCAA compliant accounting software
10 keys to evaluating DCAA compliant accounting softwareDassian Inc.
 
Dassian Workforce Authorization Management (WAM)
Dassian Workforce Authorization Management (WAM)Dassian Workforce Authorization Management (WAM)
Dassian Workforce Authorization Management (WAM)Dassian Inc.
 

En vedette (14)

Conditioned Air Resume
Conditioned Air ResumeConditioned Air Resume
Conditioned Air Resume
 
JustinBrooks_NCUR2016_UofMemphis_Presentation
JustinBrooks_NCUR2016_UofMemphis_PresentationJustinBrooks_NCUR2016_UofMemphis_Presentation
JustinBrooks_NCUR2016_UofMemphis_Presentation
 
Agile project-estimation-and-planning-e mag
Agile project-estimation-and-planning-e magAgile project-estimation-and-planning-e mag
Agile project-estimation-and-planning-e mag
 
Structural Trauma and Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma and Toxic Stress: Lifecourse Roots of Health InequitiesStructural Trauma and Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma and Toxic Stress: Lifecourse Roots of Health Inequities
 
Sme spokane event summaries
Sme spokane event summariesSme spokane event summaries
Sme spokane event summaries
 
Copy Of Po# 4286215
Copy Of Po# 4286215Copy Of Po# 4286215
Copy Of Po# 4286215
 
dillard's 2008proxystatement
dillard's 2008proxystatementdillard's 2008proxystatement
dillard's 2008proxystatement
 
Structural Trauma & Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma & Toxic Stress: Lifecourse Roots of Health InequitiesStructural Trauma & Toxic Stress: Lifecourse Roots of Health Inequities
Structural Trauma & Toxic Stress: Lifecourse Roots of Health Inequities
 
dillard's annual reports 2007
dillard's annual reports 2007dillard's annual reports 2007
dillard's annual reports 2007
 
dillard's annual reports 2005
dillard's annual reports 2005dillard's annual reports 2005
dillard's annual reports 2005
 
dillard's annual reports 2006
dillard's annual reports 2006dillard's annual reports 2006
dillard's annual reports 2006
 
dillard's annual reports 2004
dillard's annual reports 2004dillard's annual reports 2004
dillard's annual reports 2004
 
10 keys to evaluating DCAA compliant accounting software
10 keys to evaluating DCAA compliant accounting software10 keys to evaluating DCAA compliant accounting software
10 keys to evaluating DCAA compliant accounting software
 
Dassian Workforce Authorization Management (WAM)
Dassian Workforce Authorization Management (WAM)Dassian Workforce Authorization Management (WAM)
Dassian Workforce Authorization Management (WAM)
 

Similaire à Data structures and algorithms lab4

Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3Bianca Teşilă
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
Introduction and BackgroundIn recent lectures we discussed usi.pdf
Introduction and BackgroundIn recent lectures we discussed usi.pdfIntroduction and BackgroundIn recent lectures we discussed usi.pdf
Introduction and BackgroundIn recent lectures we discussed usi.pdfarpitaeron555
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.comclaric64
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comGVlaxmi7
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxrangariprajwal4554
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.pptsoniya555961
 
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docxAssg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docxfestockton
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comledlang1
 
ECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comshanaabe90
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 

Similaire à Data structures and algorithms lab4 (20)

Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
Introduction and BackgroundIn recent lectures we discussed usi.pdf
Introduction and BackgroundIn recent lectures we discussed usi.pdfIntroduction and BackgroundIn recent lectures we discussed usi.pdf
Introduction and BackgroundIn recent lectures we discussed usi.pdf
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.com
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.com
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docxAssg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
 
Lab Manual-OOP.pdf
Lab Manual-OOP.pdfLab Manual-OOP.pdf
Lab Manual-OOP.pdf
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
 
Lec2
Lec2Lec2
Lec2
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.com
 
ECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.com
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Chapter11
Chapter11Chapter11
Chapter11
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 

Plus de Bianca Teşilă

Akka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive storyAkka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive storyBianca Teşilă
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11Bianca Teşilă
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10Bianca Teşilă
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9Bianca Teşilă
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8Bianca Teşilă
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7Bianca Teşilă
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6Bianca Teşilă
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5Bianca Teşilă
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2Bianca Teşilă
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1Bianca Teşilă
 

Plus de Bianca Teşilă (10)

Akka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive storyAkka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive story
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
 

Data structures and algorithms lab4

  • 1. DATA STRUCTURES AND ALGORITHMS LAB 4 Bianca Tesila FILS, March 2014
  • 2. OBJECTIVES Queue  Queue vs stack  Applications 
  • 3. QUEUES  instance of an abstract data type (ADT) that formalizes the concept of restricted collection (FIFO = first in first out)
  • 4. QUEUES: BASIC OPERATIONS  enqueue(x)   dequeue()    Removes the element from the head of the queue and returns it Returns an error if the stack is empty peek()   Adds the element x at the tail of the queue Returns (but does not remove) the element at the head of the queue isEmpty()  Returns 1 if the queue is empty and 0 otherwise
  • 5. QUEUES: IMPLEMENTATION   with a static data structure (array, circular array) with a dynamic data structure (list) ‼Short reminder: Why do we use circular arrays instead of simple arrays?
  • 8. QUEUES VS STACKS ‼Exercise: Implement a stack using 2 queues. The corresponding class is QueuedStack and has the following methods:  an empty constructor  destructor  push  pop There are several solutions for this task. Using a similar approach, implement a queue using 2 stacks: StackedQueue.
  • 9. QUEUES AND STACKS: APPLICATIONS ‼Exercise: Implement a stack which provides an efficient get minimum function along with regular push and pop functionality. Hint: use an auxiliary stack. Taking into consideration that a queue can be implemented using 2 stacks, use a similar approach for getting the minimum element out of a queue.
  • 10. HOMEWORK o Finish all the lab exercises. o Implement a messaging system using queues.   Messages are received in the order they are sent You should use the following classes:        Message MessageSender MessageReceiver A Message object has a sender, recipient, content (make an array of chars!!) and a date A Message is placed in a queue by a MessageSender object A Message is removed from a queue by a MessageReceiver object, which can also display the content of the message. Your queue class can receive any types of objects, including Message Objects