Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-2pzkn Total loading time: 0 Render date: 2024-05-21T07:25:07.950Z Has data issue: false hasContentIssue false

1 - Elementary Structures

Published online by Cambridge University Press:  25 January 2011

Peter Brass
Affiliation:
City College, City University of New York
Get access

Summary

Elementary data structures usually treated in the “Programming 2” class are the stack and the queue. They have a common generalization, the double-ended queue, which is also occasionally mentioned, although it has far fewer applications. Stack and queue are very fundamental structures, so they will be discussed in detail and used to illustrate several points in data structure implementation.

Stack

The stack is the simplest of all structures, with an obvious interpretation: putting objects on the stack and taking them off again, with access possible only to the top item. For this reason they are sometimes also described as LIFO storage: last in, first out. Stacks occur in programming wherever we have nested blocks, local variables, recursive definitions, or backtracking. Typical programming exercises that involve a stack are the evaluation of arithmetic expressions with parentheses and operator priorities, or search in a labyrinth with backtracking.

The stack should support at least the following operations:

  • {push (obj): Put obj on the stack, making it the top item.

  • {pop (): Return the top object from the stack and remove it from the stack.

  • {stack empty (): Test whether the stack is empty.

Also, the realization of the stack has, of course, to give the right values, so we need to specify the correct behavior of a stack. One method would be an algebraic specification of what correct sequences of operations and return values are.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2008

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Elementary Structures
  • Peter Brass, City College, City University of New York
  • Book: Advanced Data Structures
  • Online publication: 25 January 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511800191.002
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Elementary Structures
  • Peter Brass, City College, City University of New York
  • Book: Advanced Data Structures
  • Online publication: 25 January 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511800191.002
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Elementary Structures
  • Peter Brass, City College, City University of New York
  • Book: Advanced Data Structures
  • Online publication: 25 January 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511800191.002
Available formats
×