🍁
Data Structures and Algorithms
  • Introduction
  • Introduction to Algorithms Analysis
    • Growth Rates
    • Big-O, Little-o, Theta, Omega
    • Analysis of Linear Search
    • Analysis of Binary Search
  • Recursion
    • The runtime stack
    • How to Write a Recursive Function
      • Example: the Factorial Function
    • Drawbacks of Recursion and Caution
  • Lists
    • Implementation
    • Linked List
      • Nodes
      • Iterator
      • Template Singly Linked List
      • Doubly Linked List
      • Circular Linked List
  • Stacks
    • Stack Operations
    • Stack Implementations
    • Stack Applications
  • Queue
    • Queue Operations
    • Queue Implementations
    • Queue Applications
  • Tables
    • Simple Table
    • Hash Table
      • Bucketing
      • Chaining
      • Linear Probing
      • Quadratic Probing and Double Hashing
  • Sorting
    • Simple Sorts
      • Bubble Sort
      • Insertion Sort
      • Selection Sort
    • Merge Sort
      • Merge Sort Implementation
    • Quick Sort
    • Heap Sort
      • Binary heap
      • Binary heap basics
      • Insertion into a binary heap
      • Delete from a binary heap
      • Implementation
      • Sorting
  • Introduction to Trees, Binary Search Trees
    • Definitions
    • Tree Implementations
    • Binary Trees
    • Binary Search Trees
      • Insertion
      • Removal
      • Traversals
  • AVL Trees
    • Height Balance
    • Insertion
    • Why it works
  • Red Black Trees
    • Insertion Example
  • 2-3 Trees
  • Graphs
    • Representation
  • Complexity Theory
  • Appendix: Mathematics Review
Powered by GitBook
On this page
  • Bracket checking
  • Postfix expression calculator

Was this helpful?

  1. Stacks

Stack Applications

Bracket checking

One example of application of a stack is in checking that bookend semantics such as brackets are properly matched. That is if you have an expresion containing various brackets, the function would tell you if the brackets are correctly placed and matched.

int bracketcheck(char expr[]);

returns true if expr is a string where (), {} and [] brackets are properly matched. false if not.

Postfix expression calculator

The way we write expressions uses infix notation. In other words, all operations look like A operator B (operator is "in" the middle of the expression). In order to change the order of operations, we must use (). Order of operations also matter

Another way to write expressions is to use postfix expression. All operations look like A B operator (the operator is after the operands) The advantage of postfix expressions is that brackets are not needed and order of operators are not needed. Example: infix

(1+2) - 3* (4+5)

equivalent postfix:

1 2 + 3 4 5 + * -

Some calculators actually use postfix notation for entry.

PreviousStack ImplementationsNextQueue

Last updated 5 years ago

Was this helpful?