SlideShare a Scribd company logo
1 of 18
Download to read offline
Programación II
Clase práctica 8: Uso del TDA Cola
M. Sc. Leandro Tabares Martín, P. As.
https://www.slideshare.net/LeandroTabaresMartn, ltmartin@uci.cu
Objetivo
Utilizar el TDA Cola en la solución
de problemas.
Bibliografía
Heileman, G.; Estructuras de datos,
algoritmos y programación orientada a
objetos. Capítulo 6.
Aho, V., Hopcroft, J., Ullman, J.;
Estructuras de datos y algoritmos.
Capítulo 2, epígrafes 2.3 y 2.4.
Revisión del estudio
independiente
Write a method splitStack that takes a stack of integers as
a parameter and splits it into negatives and non-negatives.
The numbers in the stack should be rearranged so that all
the negatives appear on the bottom of the stack and all the
non-negatives appear on the top. In other words, if after
this method is called you were to pop numbers off the
stack, you would first get all the nonnegative numbers and
then get all the negative numbers. It does not matter what
order the numbers appear in as long as all the negatives
appear lower in the stack than all the non-negatives. You
may use a single queue as auxiliary storage.
Ejercicio 1
¿Qué salida produce el siguiente
fragmento de código?
Ejercicio 1
1- Abrir la siguiente URL:
https://practiceit.cs.washington.edu/
problem/view/bjp3/chapter14/s15-
stackQueueUsage3
2- Autenticarse.
3- Introducir la respuesta del ejercicio.
4- Oprimir “Submit”.
Ejercicio 2
Abrir la URL:
https://practiceit.cs.washington.edu/
problem/view/bjp3/chapter14/s16-
stackQueueMystery1
Ejercicio 3
Write a method rearrange that takes
a queue of integers as a parameter
and rearranges the order of the
values so that all of the even values
appear before the odd values and
that otherwise preserves the original
order of the list.
Ejercicio 3
For example, suppose a queue called q stores this
sequence of values:
front [3, 5, 4, 17, 6, 83, 1, 84, 16, 37] back
Then the call of rearrange(q); should rearrange the
queue to store the following sequence of values:
front [4, 6, 84, 16, 3, 5, 17, 83, 1, 37] back
Ejercicio 3
Notice that all of the evens appear
at the front of the queue followed by
the odds and that the order of the
evens is the same as in the original
list and the order of the odds is the
same as in the original list. You may
use one stack as auxiliary storage.
Ejercicio 3
1- Abrir la URL:
https://practiceit.cs.washington.edu/
problem/view/bjp3/chapter14/e6-rearrange
2- Autenticarse
3- Introducir la solución del ejercicio
4- Oprimir “Submit”
Estudio independiente
Resolver el ejercicio en la URL
https://practiceit.cs.washington.edu/
problem/view/bjp3/chapter14/e7-
reverseHalf
Estudio independiente
Write a method reverseHalf that
reverses the order of half of the
elements of a Queue of integers. Your
method should reverse the order of all
the elements in odd-numbered positions
(position 1, 3, 5, etc.) assuming that the
first value in the queue has position 0.
Estudio independiente
For example, if the queue originally stores this
sequence of numbers when the method is called:
●
- it should store the following values after the method
finishes executing:
index 0 1 2 3 4 5 6 7
front 1 8 7 2 9 18 12 0 back
index 0 1 2 3 4 5 6 7
front 1 0 7 18 9 2 12 8 back
Estudio independiente
Notice that numbers in even positions
(positions 0, 2, 4, 6) have not moved. That
sub-sequence of numbers is still: (1, 7, 9,
12). But notice that the numbers in odd
positions (positions 1, 3, 5, 7) are now in
reverse order relative to the original. In other
words, the original sub-sequence: (8, 2, 18,
0) - has become: (0, 18, 2, 8). You may use a
single stack as auxiliary storage.
Programación II
Clase práctica 8: Uso del TDA Cola
M. Sc. Leandro Tabares Martín, P. As.
https://www.slideshare.net/LeandroTabaresMartn, ltmartin@uci.cu

More Related Content

Similar to Clase práctica 8: Uso del TDA Cola

Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
auswhit
 
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docxCMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
mary772
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
Jabs6
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
shailaja30
 

Similar to Clase práctica 8: Uso del TDA Cola (20)

Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptxLecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptx
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62
 
Algo PPT.pdf
Algo PPT.pdfAlgo PPT.pdf
Algo PPT.pdf
 
Shell sorting
Shell sortingShell sorting
Shell sorting
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docxCMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
 
Team 3
Team 3Team 3
Team 3
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
 
one main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to othersone main advantage of bubble sort as compared to others
one main advantage of bubble sort as compared to others
 
(7) Inquiry Lab - Add and Subtract on the Number Line
(7) Inquiry Lab - Add and Subtract on the Number Line(7) Inquiry Lab - Add and Subtract on the Number Line
(7) Inquiry Lab - Add and Subtract on the Number Line
 
Stack organization
Stack organizationStack organization
Stack organization
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 

Clase práctica 8: Uso del TDA Cola

  • 1. Programación II Clase práctica 8: Uso del TDA Cola M. Sc. Leandro Tabares Martín, P. As. https://www.slideshare.net/LeandroTabaresMartn, ltmartin@uci.cu
  • 2. Objetivo Utilizar el TDA Cola en la solución de problemas.
  • 3. Bibliografía Heileman, G.; Estructuras de datos, algoritmos y programación orientada a objetos. Capítulo 6. Aho, V., Hopcroft, J., Ullman, J.; Estructuras de datos y algoritmos. Capítulo 2, epígrafes 2.3 y 2.4.
  • 4. Revisión del estudio independiente Write a method splitStack that takes a stack of integers as a parameter and splits it into negatives and non-negatives. The numbers in the stack should be rearranged so that all the negatives appear on the bottom of the stack and all the non-negatives appear on the top. In other words, if after this method is called you were to pop numbers off the stack, you would first get all the nonnegative numbers and then get all the negative numbers. It does not matter what order the numbers appear in as long as all the negatives appear lower in the stack than all the non-negatives. You may use a single queue as auxiliary storage.
  • 5. Ejercicio 1 ¿Qué salida produce el siguiente fragmento de código?
  • 6.
  • 7. Ejercicio 1 1- Abrir la siguiente URL: https://practiceit.cs.washington.edu/ problem/view/bjp3/chapter14/s15- stackQueueUsage3 2- Autenticarse. 3- Introducir la respuesta del ejercicio. 4- Oprimir “Submit”.
  • 8. Ejercicio 2 Abrir la URL: https://practiceit.cs.washington.edu/ problem/view/bjp3/chapter14/s16- stackQueueMystery1
  • 9.
  • 10. Ejercicio 3 Write a method rearrange that takes a queue of integers as a parameter and rearranges the order of the values so that all of the even values appear before the odd values and that otherwise preserves the original order of the list.
  • 11. Ejercicio 3 For example, suppose a queue called q stores this sequence of values: front [3, 5, 4, 17, 6, 83, 1, 84, 16, 37] back Then the call of rearrange(q); should rearrange the queue to store the following sequence of values: front [4, 6, 84, 16, 3, 5, 17, 83, 1, 37] back
  • 12. Ejercicio 3 Notice that all of the evens appear at the front of the queue followed by the odds and that the order of the evens is the same as in the original list and the order of the odds is the same as in the original list. You may use one stack as auxiliary storage.
  • 13. Ejercicio 3 1- Abrir la URL: https://practiceit.cs.washington.edu/ problem/view/bjp3/chapter14/e6-rearrange 2- Autenticarse 3- Introducir la solución del ejercicio 4- Oprimir “Submit”
  • 14. Estudio independiente Resolver el ejercicio en la URL https://practiceit.cs.washington.edu/ problem/view/bjp3/chapter14/e7- reverseHalf
  • 15. Estudio independiente Write a method reverseHalf that reverses the order of half of the elements of a Queue of integers. Your method should reverse the order of all the elements in odd-numbered positions (position 1, 3, 5, etc.) assuming that the first value in the queue has position 0.
  • 16. Estudio independiente For example, if the queue originally stores this sequence of numbers when the method is called: ● - it should store the following values after the method finishes executing: index 0 1 2 3 4 5 6 7 front 1 8 7 2 9 18 12 0 back index 0 1 2 3 4 5 6 7 front 1 0 7 18 9 2 12 8 back
  • 17. Estudio independiente Notice that numbers in even positions (positions 0, 2, 4, 6) have not moved. That sub-sequence of numbers is still: (1, 7, 9, 12). But notice that the numbers in odd positions (positions 1, 3, 5, 7) are now in reverse order relative to the original. In other words, the original sub-sequence: (8, 2, 18, 0) - has become: (0, 18, 2, 8). You may use a single stack as auxiliary storage.
  • 18. Programación II Clase práctica 8: Uso del TDA Cola M. Sc. Leandro Tabares Martín, P. As. https://www.slideshare.net/LeandroTabaresMartn, ltmartin@uci.cu