Stacks - Chapter 3 PDF

Summary

This document explains stacks, a fundamental data structure in computer science. It details stack operations, including push and pop, and provides examples of how stacks are used in programming.

Full Transcript

Stacks CHAPTER 3 Objectives Students are expected to: Define stack data structure Identify the different ways to represent stack Examine the stack operation algorithms Apply stack operation algorithms in converting mathematical expressions Compare the difference of queue and stack data stru...

Stacks CHAPTER 3 Objectives Students are expected to: Define stack data structure Identify the different ways to represent stack Examine the stack operation algorithms Apply stack operation algorithms in converting mathematical expressions Compare the difference of queue and stack data structure Stacks A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example in the picture shown below. Stacks An ordered list where all operations are restricted at one end of the list known as the TOP. The last element inserted into the stack will always be the first one processed. This type of behavior in list processing is called LIFO or Last-in-First-Out. Stacks Representation There are several ways to represent a stack: (1) as a one-dimensional array, (2) structure, (3) pointer, (4) linked list. Algorithm for PUSH operation Algorithm for POP operation

Use Quizgecko on...
Browser
Browser