Esdap Unit 4 Activity 2
Esdap Unit 4 Activity 2
PRESENTA:
Introduction ........................................................................................... 1
Stacks ....................................................................................................... 2
Recursion in Programming .......................................................................... 2
Queues ..................................................................................................... 4
Shared Printers .......................................................................................... 4
Conclusion ............................................................................................... 6
I
Table of Figure.
FIGURE PAGE
Figure 1 Example stack .................................................................................. 3
Figure 2 Example of Queues........................................................................... 5
II
Introduction
1
Stacks
Recursion in Programming
2
In a job or task processing system, when several jobs have to be executed in
reverse order, a stack may be used. For example, in a printing system where jobs
are stacked and printed in reverse order of arrival.
Why it is useful: Ensures that the most recent jobs are processed first, ideal for
certain resource management applications.
A stack is a data structure that follows the LIFO (Last In, First Out) principle. This
means that the last element to be added to the stack is the first to be removed.
3
Queues
A queue is a module that allows you to implement queues, which are linear data
structures that follow the FIFO (first in, first out) rule.
Shared Printers
When several people send documents to a printer, the jobs are placed in a print
queue. The job that arrives first will be the first to be printed.
Why it is useful: Ensures that documents are printed in the order in which they
were sent, preventing anyone from having to wait indefinitely.
Operating systems manage tasks in queues. When a task is waiting (for example,
waiting for disk or CPU access), it is placed in the task queue. The operating
system processes the tasks in the order in which they arrive.
Why it is useful: Ensures that tasks are managed fairly and efficiently, following
the FIFO principle.
4
Vehicle traffic at an intersection with traffic lights works like a queue. Vehicles
arrive and line up, and the traffic light allows them to pass in the order in which
they arrived.
Why it is useful: It organizes the flow of traffic, ensuring that all vehicles pass in
an orderly fashion, without skipping a turn.
5
Conclusion
In conclusion, this document looks at the use of stacks and queues in object-
oriented programming to solve some problems. The abstraction and
encapsulation offered by classes makes it easier to handle these structures,
making their use intuitive and modular. This not only improves the readability and
maintainability of the code, but also allows reuse and extension of functionality
according to the specific needs of the problem. With this approach, efficiency in
problem solving is achieved, from the validation of mathematical expressions to
the management of tasks in operating systems, thus demonstrating its usefulness
in different real-life contexts.