0% found this document useful (0 votes)
8 views

2B-Queues - Practice

csd021

Uploaded by

huyngse180366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

2B-Queues - Practice

csd021

Uploaded by

huyngse180366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Data Structures and Algorithms

★ Stack & Queue – Practice ★

Dr Vi Chi Thanh – [email protected]


https://vichithanh.github.io
Practice - Stack

• See file StackApp.java


• Practice:
• Write methods to display the stack array and the stack itself. Use them to
trace the stack operation.
• Extend the push and pop methods to deal with a full and empty stack.

THURSDAY, 21 SEPTEMBER 2023 2


Practice - Stack

• See file ReverseApp.java


• Practice:
• Create a stack of objects of class Person and use to reverse a list of persons.

THURSDAY, 21 SEPTEMBER 2023 3


Practice - Queue

• See file QueueApp.java


• Practice:
• Write a method to display the queue array and the front and rear indices.
Understand how wraparound works.
• Display the array, the queue, and the front and rear indices.
• Insert fewer items or remove fewer items and investigate what happens when
the queue is empty or full.
• Extend the insert and remove methods to deal with a full and empty queue.

THURSDAY, 21 SEPTEMBER 2023 4


Practice – Priority Queue

• Look at file PriorityQApp.java


• Write a method to display the queue and use to trace the queue
operation.
• Modify the insert method to insert the new item at the rear.

THURSDAY, 21 SEPTEMBER 2023 5


THANK YOU

Dr Vi Chi Thanh – [email protected]


https://vichithanh.github.io

You might also like