Stacks and queues

Objectives

  • Use stacks to store and retrieve data
  • Use queues to store and retrieve data
  • Use templating to make linked lists, stacks, and queues more general
  • Use dynamic memory allocation to make data structures more memory efficient

Overview

These topics are covered in detail in the text, so these notes won't bother reiterating them. The class session will discuss some topics in detail, and then illustrate their implementation with some of the programs listed on this page. If you don't have the text, then you can get most of the details of the data structures we will be discussing using Wikipedia:

Templates, Stacks, Queues, Deques

  • Note: linked lists may not have a particular removal order
  • Note: stacks are LIFO (last in, first out data structures)
  • Note: queues are FIFO (first in, first out data structures)
  • Templated linked lists:
    • See MyObj.h: simple class used for filling tlist
    • See tlist.h: implementation of templated linked list class using dynamic memory allocation
    • See TestTList.cpp: test driver for tlist.h
    • See gll.h: implementation of templated linked list class using reference variables
    • See testgll.cpp: test driver for gll.h
  • Stack: stack.h       TestStack1.cpp
  • Stack with templating: stackt.h       TestStack2.cpp
  • Stack with dynamic allocation and templating: stackd.h       TestStack3.cpp
  • Queue with dynamic allocation and templating: queued.h       TestQueue3.cpp