Stacks by Constance Royden

Stacks by Constance - Data Structures CSCI 132 Spring 2006 Lecture 5 Stacks 1 Lists • A list is an abstract data type consisting of an ordered

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Data Structures CSCI 132, Spring 2006 Lecture 5 Stacks 2 Lists A list is an abstract data type consisting of an ordered group of items. A list is dynamic. Its length can vary. Items can be added to or deleted from the list There are many ways of implementing a list. For example: An array Linked lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3 Arrays Arrays in C++ have fixed length. Arrays can be used to implement lists. A separate variable must keep track of the length of the list in the array. 4 Example /*Write a program to read in positive integers and store them in an array until a negative number is encountered.*/ int main(void) { int myList[30]; int count = 0; cin >> myList[0]; //read first number while (myList[count] >= 0 ) { count++; cin >> myList[count]; //read in next number } }
Background image of page 2
5 Stacks A stack is a list that has addition and deletion of items only from one end. It is like a stack of plates: Plates can be added to the top of the stack. Plates can be removed from the top of the stack.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2010 for the course CPE CPE 360 taught by Professor Jenniferchen during the Spring '10 term at Stevens.

Page1 / 10

Stacks by Constance - Data Structures CSCI 132 Spring 2006 Lecture 5 Stacks 1 Lists • A list is an abstract data type consisting of an ordered

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online