notes43

notes43 - CS251 NOTES ON WEEK OF JAN22 Ramsey Saba /* These...

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

View Full Document Right Arrow Icon
CS251 NOTES ON WEEK OF JAN22 Ramsey Saba /* These are notes that are based off what the teacher wrote on the board and some added content to help my understanding. If you have any questions regarding the following notes please feel free to email me at rsaba@purdue.edu*/ Stacks, Queues and Linked Lists Stacks: Container of objects that are inserted and removed according to the last-in first-out principle (LIFO) Two-operations: Push(o) – insert item on top of stack Pop(o) – remove item from top of stack Uses: Store local variables and return addresses Evaluating equations in RPN: -used in HP calculators -Post Script (printer language) -JVM (Java virtual machine) Standard RPN 3 + 2 3 2 + C++ : StackDouble.h: (interface) Class stackdouble { Double _stack[]; // array storing stack Int _n; //number of elements in stack Int _max; // maximum size of stack Public: Class stackdouble(int max);
Background image of page 1

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

View Full DocumentRight Arrow Icon
Bool push(double val); //true if success, false if fails Bool pop (double *pval); //pops element from stack //return true if success false if fails //pval contains popped value Bool isEmpty(); //true if stack is empty, otherwise false } Stackdouble.cpp (implementation) #include <assert.h> #include “stackdouble.h” Stackdouble::stackdouble(int max){ _stack = new double[max]; Assert(_stack != NULL ) _n = 0; _max = max; } Bool stackdouble::push(double val){ If (_n == max) Return false // stack is full _stack[_n] = val; _n++; Return true; } Bool stackdouble::pop(double *pval){ If (_n == 0) Return false // stack is empty *pval = _stack[_n-1]; _n--; Return true; } Bool stackdouble::isEmpty(){ Return(_n==0); }
Background image of page 2
Implementing a stack using a list -points to head of the list
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.

Page1 / 10

notes43 - CS251 NOTES ON WEEK OF JAN22 Ramsey Saba /* These...

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