classes-1

classes-1 - Preliminaries Implementation of a Simple...

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

View Full Document Right Arrow Icon
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes C ++ Classes Len Blanks CSC 1253 Introduction To Computer Science I Using C ++ Louisiana State University November 10, 2010 Len Blanks C ++ Classes
Background image of page 1

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

View Full DocumentRight Arrow Icon
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes Topics 1 Preliminaries 2 Implementation of a Simple Integer Stack—with Structs 3 Implementation of a Simple Integer Stack—with Classes Len Blanks C ++ Classes
Background image of page 2
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes References The material for this lecture is heavily based on content from The C ++ Programming Language by Bjarne Stroustrup. Big C ++ by Cay Horstmann and Timothy Budd. Len Blanks C ++ Classes
Background image of page 3

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

View Full DocumentRight Arrow Icon
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes Integer Stack Using a Struct /** * Stack * A set of routines to implement a simple integer * stack. * * Procedures * stack_init -- initalise the stack. * stack_push -- insert an item on the stack. * stack_pop -- remove an item from the stack. * stack_top -- returns the item atop the stack. */ #include <cstdlib> #include <iostream> using namespace std; Len Blanks C ++ Classes
Background image of page 4
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes Integer Stack Using a Struct struct Stack { int top; // Position (index) of the stack top int contents[STACKSIZE]; // The items themselves }; Len Blanks C ++ Classes
Background image of page 5

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

View Full DocumentRight Arrow Icon
Preliminaries Implementation of a Simple Integer Stack—with Structs Implementation of a Simple Integer Stack—with Classes Integer Stack Using a Struct void stack init(Stack &the_stack) { /* * Initialise the stack the stack * @param the stack the stack to initialise */ the stack.top = -1; // Start with empty stack } void stack push(Stack &the stack, const int item) { /* * Insert item atop the stack * Warning: There is no check for stack overflow.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

classes-1 - Preliminaries Implementation of a Simple...

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

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