









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An example of converting an infix expression to postfix notation using a stack. It also explains how to implement a stack in c++ using templates. The code for a stack class and its implementation.
Typology: Slides
1 / 16
This page cannot be seen from the preview
Don't miss anything!










template
class Stack {
public:
Stack(); int empty(void); // 1=true, 0=false int push(T &); // 1=successful,0=stack overflow T pop(void); T peek(void); ~Stack();
private:
int top; T* nodes;
};
#include <iostream.h> #include <stdlib.h> #include "Stack.cpp"
#define MAXSTACKSIZE 50
template
template
int Stack
{
if( top < MAXSTACKSIZE ) {
nodes[++top] = x; return 1;
}
cout << "stack overflow in push.\n";
return 0;
}
template
return address
first argument
second argument
last argument ……….
n*4(%esp)
(%esp) top
8(%esp)
4(%esp)
int i_avg (int a, int b) { return (a + b) / 2; }
.globl _i_avg
_i_avg:
movl 4(%esp), %eax
addl 8(%esp), %eax # Add the args
sarl $1, %eax # Divide by 2
ret # Return value is in %eax