0% found this document useful (0 votes)
17 views

Module 4 Stack Data Structure

The document discusses stacks as a data structure. It defines stacks as a linear data structure that follows LIFO (last in, first out) order for adding and removing elements. Common stack operations like push, pop, peek, isEmpty and isFull are described. The document provides algorithms and code examples for implementing stacks using arrays in C++. It also briefly discusses using stacks from the Standard Template Library in C++.

Uploaded by

JD Dulatre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Module 4 Stack Data Structure

The document discusses stacks as a data structure. It defines stacks as a linear data structure that follows LIFO (last in, first out) order for adding and removing elements. Common stack operations like push, pop, peek, isEmpty and isFull are described. The document provides algorithms and code examples for implementing stacks using arrays in C++. It also briefly discusses using stacks from the Standard Template Library in C++.

Uploaded by

JD Dulatre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Isabela State University, Jones Campus

IT 211 Data Structure and Algorithms

ISU MODULE TEMPLATE


Subject: IT 211 – Data Structures and Algorithms
1. Title of the Module : Module 4 – STACKS

2. Introduction

This chapter focuses on stack data structure. Stack is one of the most covered
data structure in curriculum and are often used when there are interrupts to handle, or
when having recursive functions, or even when constructing a rudimentary AI for
games. It is also a very common data structure used in programs which has lot of
potential. This part also discusses basic features, operations/applications and
implementations of stacks.

3. Learning Outcome
At the end of this chapter the students are expected to:
• Describe the stack operations.
• Perform stack operations in a program.
• Evaluate arithmetic expressions in stacks.

4. Learning Content
Stack is an abstract data type with a bounded(predefined) capacity. It is a simple
data structure that allows adding and removing elements in a particular order. Every
time an element is added, it goes on the top of the stack and the only element that can
be removed is the element that is at the top of the stack, just like a pile of objects. It is
a first-in-last-out data structure with access only to the top of the data. Since many
languages does not provide facility for stack, it is backed by either arrays or linked list.
The values can be added and deleted on any side from an array. But in stack, insertion
and deletion is possible on only one side of the stack. Stacks hold objects, usually all
of the same type. It follows the concept of LIFO – last in first out where values can be
inserted (pushed) onto a stack or removed (popped) from the stack, and the value that
was pushed on the stack most recently is the first to be popped from it. Stack is a linear
list of items in which all additions and deletion are restricted to one end. Some
languages, like LISP and Python, do not call for stack implementations, since push and
pop functions are available for any list. All Forth-like languages (such as Adobe
PhotoScript) are also designed around language-defined stacks that are directly visible
to and manipulated by the programmer. Stacks holds objects. Common stack
operations are pop, push, peek (get the top element without removing it), is Empty
(checks whether stack is empty or not), and is Full (checks whether stack is full
or not).

Module 4 Stacks Page 1 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

4.1. Stack Operations


Stack operations may involve initializing the stack, using it and then
deinitializing it. Apart from these basic stuffs, a stack is used for the following two
primary operations.
• push() − Pushing (storing) an element on the stack.
• pop() − Removing (accessing) an element from the stack.
Note: To use a stack efficiently, we need to check the status of stack as well. For the same
purpose, the following functionality is added to stacks.
• peek() − get the top data element of the stack, without removing it.
• isFull() − check if stack is full.
• isEmpty() − check if stack is empty.
At all times, we maintain a pointer to the last PUSHed data on the stack. As this
pointer always represents the top of the stack, hence named top. The top pointer provides
top value of the stack without actually removing it.
Procedures to support stack functions: peek()

Algorithm of peek() function − begin


procedure peek
return stack[top] end
procedure
Implementation of peek() function in C programming language:
Example
int peek() { return
stack[top];
} isfull()
Algorithm of isfull() function − begin
procedure isfull

if top equals to MAXSIZE


return true
else return
false endif

end procedure
Implementation of isfull() function in C programming language:
Example
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

bool isfull() {
if(top== MAXSIZE)
return true; else
return false;
}
isempty()
Algorithm of isempty() function − begin
procedure isempty

if top less than 1


return true else
return false endif

end procedure
Implementation of isempty() function in C programming language is slightly different. We
initialize top at -1, as the index in array starts from 0. So we check if the top is below zero
or -1 to determine if the stack is empty. Here's the code:
Example
bool isempty() {
if(top == -1)
return true; else
return false;
}

4.1.1 Push Operation


The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps:
• Step 1 − Checks if the stack is full.
• Step 2 − If the stack is full, produces an error and exit.
• Step 3 − If the stack is not full, increments top to point next empty space.
• Step 4 − Adds data element to the stack location, where top is pointing.
• Step 5 − Returns success.

Module 4 Stacks Page 3 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

If the linked list is used to implement the stack, then in step 3, we need to allocate
space dynamically.

4.1.1a Algorithm for PUSH Operation


A simple algorithm for Push operation can be derived as follows:
begin procedure push: stack, data

1. Check if the stack is full or not.


2. If the stack is full, then print error of overflow and exit the program.
3. If the stack is not full, then increment the top and add the element.

if stack is full
return null endif

top ← top + 1
stack[top] ← data

end procedure
Implementation of this algorithm in C, is very easy. See the following code:
Example
void push(int data) {
if(!isFull()) { top
= top + 1;
stack[top] = data;
} else {
printf("Could not insert data, Stack is full.\n");
}
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

}
4.1.2. Pop Operation
Accessing the content while removing it from the stack, is known as a Pop Operation. In
an array implementation of pop() operation, the data element is not actually removed,
instead top is decremented to a lower position in the stack to point to the next value. But
in linked-list implementation, pop() actually removes data element and deallocates
memory space.
A Pop operation may involve the following steps −
• Step 1 − Checks if the stack is empty.
• Step 2 − If the stack is empty, produces an error and exit.
• Step 3 − If the stack is not empty, accesses the data element at which topis pointing.
• Step 4 − Decreases the value of top by 1.
• Step 5 − Returns success.

4.1.2a Algorithm for Pop Operation


A simple algorithm for Pop operation can be derived as follows − begin
procedure pop: stack

1. Check if the stack is empty or not.


2. If the stack is empty, then print error of underflow and exit the program.
3. If the stack is not empty, then print the element at the top and decrement the top.

Module 4 Stacks Page 5 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

if stack is empty
return null endif

data ← stack[top]
top ← top - 1 return
data

end procedure
Implementation of this algorithm in C, is as follows:
Example
int pop(int data) {

if(!isempty()) {
data = stack[top];
top = top - 1;
return data; } else {

4.2 Stack Implementation


Stack can be easily implemented using an Array or a Linked List. Arrays are quick,
but are limited in size and Linked List requires overhead to allocate, link, unlink, and
deallocate, but is not limited in size. Here we will implement Stack using array.

4.2.1 Implementation of Stack in C++


Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

Below is a simple C++ program that implements stack data structure and also follows
the object-oriented programming (abstract data type) concepts.
# include<iostream>
using namespace std;

class Stack
{ int top;
public:
int a[10];
Stack()
{
top = -1;
}

void push(int x);


int pop(); void
isEmpty();
};

void Stack::push(int x)
{
if(top >= 10)
{
cout << "Stack Overflow \n";
}
else
{
a[++top] = x;
cout << "Element Inserted \n";
}
}

int Stack::pop()
{
if(top < 0)
{
cout << "Stack Underflow \n";
return 0;
}
else
{
int d = a[top--];

Module 4 Stacks Page 7 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

return d;
}
}

void Stack::isEmpty()
{
if(top < 0)
{
cout << "Stack is empty \n";
}
else
{
cout << "Stack is not empty \n";
}
}

int main()
{
Stack s1;
s1.push(10);
s1.push(100);
}

Position of Top Status of Stack


-1 Stack is Empty
0 Only one element in Stack
N-1 Stack is Full

N Overflow state of Stack

4.2.1a Using Stack from the Standard Template Library (STL) in C++
Now that we have clearly defined the stack as an abstract data type we will turn
our attention to using a stack with the help of the Standard Template Library (STL) in
C++.
Unlike the given code above (which implemented stack in a user defined abstract
data structure), the STL has a well written implementation of the Stack class.
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

The following stack implementation assumes that the end of the array will hold the
top element of the stack. As the stack grows (as be added on the end of the array.
pop operations will manipulate that same
//Tests the push, empty, size, pop,
and top methods of the stack end.
library. push operations occur), new items
will

#include <iostream>
#include <stack> // Calling Stack from the STL

using namespace std;

int main() {
stack<int> newStack;

newStack.push(3); //Adds 3 to the stack


newStack.push(8);
newStack.push(15);

// returns a boolean response depending on if the stack is empty or not


cout << "Stack Empty? " << newStack.empty() << endl;

// returns the size of the stack itself cout <<


"Stack Size: " << newStack.size() << endl;

// returns the topmost element of the stack cout << "Top


Element of the Stack: " << newStack.top() << endl;

// removes the topmost element of the stack


newStack.pop();

cout << "Top Element of the Stack: " << newStack.top() << endl;

cout << "Stack Size: " << newStack.size() << endl;

return 0;
}

Self Check
Q-1: Given the following sequence of stack operations, what is the top item on the stack
when the sequence is complete?

Module 4 Stacks Page 9 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

stack<int> m;

m.push(5);

m.push(12);

m.pop();

m.push(27);
cout << m.top();

A. 5
B. 12
C. 27
D. The stack is empty
Answer: _____
Q-2: Given the following sequence of stack operations, what is the top item on the stack
when the sequence is complete?

stack<int> m;

m.push(37);

m.push(56);

m.push(4); while

(!m.empty()){

m.pop();

m.pop();

}
A. 37
B. the stack is empty
C. an error will occur
D. 4
Answer: _____
4.3 Evaluation of Arithmetic Operations
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

The stack organization is very effective in evaluating arithmetic expressions. In order


to understand how stack works to evaluate arithmetic expressions, you need to
understand the concepts of arithmetic expressions.
4.3a Infix, Prefix and Postfix Expressions
When you write an arithmetic expression such as B * C, the form of the expression
provides you with information so that you can interpret it correctly. In this case we know
that the variable B is being multiplied by the variable C since the multiplication operator *
appears between them in the expression. This type of notation is referred to as infix since
the operator is in between the two operands that it is working on.
Consider another infix example, A + B * C. The operators + and * still appear
between the operands, but there is a problem. Which operands do they work on first?
Does the + work on A and B or does the * take B and C? The expression seems
ambiguous.
In fact, you have been reading and writing these types of expressions for a long
time and they do not cause you any problem. The reason for this is that you know
something about the operators + and *. Each operator has a precedence level. Operators
of higher precedence are used before operators of lower precedence. The only thing that
can change that order is the presence of parentheses. The precedence order for
arithmetic operators places multiplication and division above addition and subtraction. If
two operators of equal precedence appear, then a left-to-right ordering or associativity is
used. Let’s interpret the troublesome expression A + B * C using operator precedence. B
and C are multiplied first, and A is then added to that result. (A + B) * C would force the
addition of A and B to be done first before the multiplication. In expression A + B + C, by
precedence (via associativity), the leftmost + would be done first.
Although all this may be obvious to you, remember that computers need to know
exactly what operators to perform and in what order. One way to write an expression that
guarantees there will be no confusion with respect to the order of operations is to create
what is called a fully parenthesized expression. This type of expression uses one pair
of parentheses for each operator. The parentheses dictate the order of operations; there
is no ambiguity. There is also no need to remember any precedence rules.
The expression A + B * C + D can be rewritten as ((A + (B * C)) + D) to show that
the multiplication happens first, followed by the leftmost addition. A + B + C + D can be
written as (((A + B) + C) + D) since the addition operations associate from left to right.
There are two other very important expression formats that may not seem obvious
to you at first. Consider the infix expression A + B. What would happen if we moved the
operator before the two operands? The resulting expression would be + A B. Likewise,
we could move the operator to the end. We would get A B +. These look a bit strange.
These changes to the position of the operator with respect to the operands create
two new expression formats, prefix and postfix. Prefix expression notation requires that
all operators precede the two operands that they work on. Postfix, on the other hand,

Module 4 Stacks Page 11 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

requires that its operators come after the corresponding operands. A few more examples
should help to make this a bit clearer (see tables below).
In prefix, A + B * C would be written as + A * B C . The multiplication operator
comes immediately before the operands B and C, denoting that * has precedence over +.
The addition operator then appears before the A and the result of the multiplication.
In postfix, the expression A + B * C would be A B C * +. Again, the order of
operations is preserved since the * appears immediately after the B and the C, denoting
that * has precedence, with + coming after. Although the operators moved and now
appear either before or after their respective operands, the order of the operands stayed
exactly the same relative to one another.
4.3.1 Examples of Infix, Prefix, and Postfix

Common Expression

Infix Expression Prefix Expression Postfix Expression

A+B +AB AB+

A+B*C +A*BC ABC*+

An Expression with Parentheses

Infix Expression Prefix Expression Postfix Expression


(A + B) * C * + A B C AB+C*

Additional Examples of Infix, Prefix, and Postfix

Infix Expression Prefix Expression Postfix Expression

A+B*C+D ++A*BCD ABC*+D+

(A + B) * (C + D) *+AB+CD AB+CD+*

A*B+C*D +*AB*CD AB*CD*+

A+B+C+D +++ABCD AB+C+D+


Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

4.3.2 Conversion of Infix Expressions to Prefix and Postfix

So far, we have used ad hoc methods to convert between infix expressions and
the equivalent prefix and postfix expression notations. As you might expect, there are
algorithmic ways to perform the conversion that allow any expression of any complexity
to be correctly transformed.
The first technique that we will consider uses the notion of a fully parenthesized
expression that was discussed earlier. Recall that A + B * C can be written as (A + (B *
C)) to show explicitly that the multiplication has precedence over the addition. On closer
observation, however, you can see that each parenthesis pair also denotes the beginning
and the end of an operand pair with the corresponding operator in the middle.
Look at the right parenthesis in the subexpression (B * C) above. If we were to
move the multiplication symbol to that position and remove the matching left parenthesis,
giving us B C *, we would in effect have converted the subexpression to postfix notation.
If the addition operator were also moved to its corresponding right parenthesis position
and the matching left parenthesis were removed, the complete postfix expression would
result (see figure below).

If we do the same thing but instead of moving the symbol to the position of the right
parenthesis, we move it to the left, we get prefix notation (see figure below). The position
of the parenthesis pair is actually a clue to the final position of the enclosed operator.

So in order to convert an expression, no matter how complex, to either prefix or


postfix notation, fully parenthesize the expression using the order of operations. Then
move the enclosed operator to the position of either the left or the right parenthesis
depending on whether you want prefix or postfix notation.
Here is a more complex expression: (A + B) * C - (D - E) * (F + G). The following
figure shows the conversion to postfix and prefix notations.

Module 4 Stacks Page 13 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

4.3.2a General Infix-to-Postfix Conversion

There is an algorithm to convert an infix expression into a postfix expression. It


uses a stack; but in this case, the stack is used to hold operators rather than numbers.
The purpose of the stack is to reverse the order of the operators in the expression. It also
serves as a storage structure, since no operator can be printed until both of its operands
have appeared.

In this algorithm, all operands are printed (or sent to output) when they are read.
There are more complicated rules to handle operators and parentheses.

Example:

A + B * C becomes A B C * +

The order in which the operators appear is not reversed. When the '+' is read, it has lower
precedence than the '*', so the '*' must be printed first.

 Algorithm
1. Create an empty stack called opstack for keeping operators. Create an empty vector
for output.
2. Scan the current token of the input vector from left to right (using a loop).
o If the token is an operand, append it to the end of the output list(vector).
o If the token is a left parenthesis, push it on the opstack.
o If the token is a right parenthesis, pop the opstack until the corresponding left
parenthesis is removed. Append each operator to the end of the output vector.
o If the token is an operator, *, /, +, or -, push it on the opstack. However, first
remove any operators already on the opstack that have higher or equal
precedence and append them to the output vector.
3. When the input expression has been completely processed, check the opstack. Any
operators still on the stack can be removed and appended to the end of the output
vector.
The following figure shows the conversion algorithm working on the expression A
* B + C * D. Note that the first * operator is removed upon seeing the + operator. Also, +
stays on the stack when the second * occurs, since multiplication has precedence over
addition. At the end of the infix expression the stack is popped twice, removing both
operators and placing + as the last operator in the postfix expression.
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

4.3.3 C++ Implementation


//Converts an infix expression to a postfix expression.

#include <iostream>
#include <stack>
#include <unordered_map>
#include <string>
#include <vector>

using namespace std;

string infixToPostfix(string infixexpr) {


//performs the postfix process.
unordered_map <char,int> prec;
prec['*']=3; prec['/']=3;
prec['+']=2;
prec['-']=2;
prec['(']=1;
stack<char> opStack;
vector<char> postfixVector;
string letsnums = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

for (char token:infixexpr) {


//for each character in infixexpr
if (token == ' ') {
continue;
}

Module 4 Stacks Page 15 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

else if (letsnums.find(token)<=letsnums.length()) { //finds if the token is inside of


let snums postfixVector.emplace_back(token); // appends to the end of the
container.
} else if (token == '(') {
opStack.push(token); }
else if (token == ')') {
char topToken;
topToken = opStack.top();
opStack.pop(); while
(topToken != '(') {
postfixVector.emplace_back(topToken);
topToken=opStack.top();
opStack.pop();
}
} else { //if the token is not inside of letsnums.
while (!opStack.empty() && (prec[opStack.top()]>=prec[token])) //while the stack
is not empty and
//the top item of the stack is on a
//higher level of PEMDAS than token.
{
postfixVector.emplace_back(opStack.top());
opStack.pop();
}
opStack.push(token);
}
}
while (!opStack.empty()) {
postfixVector.emplace_back(opStack.top());
opStack.pop();
}

string s(postfixVector.begin(),postfixVector.end());

return s;
}

int main() { cout <<"infix: A * B + C * D\n" << "postfix: "; cout <<
infixToPostfix("A * B + C * D") << endl; cout << "infix: ( A + B ) * C -
( D - E ) * ( F + G )\n" << "postfix: "; cout << infixToPostfix("( A + B )
* C - ( D - E ) * ( F + G )") << endl;

return 0;
}
Postfix Evaluation
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

As a final stack example, we will consider the evaluation of an expression that is


already in postfix notation. In this case, a stack is again the data structure of choice.
However, as you scan the postfix expression, it is the operands that must wait, not the
operators as in the conversion algorithm above. Another way to think about the solution
is that whenever an operator is seen on the input, the two most recent operands will be
used in the evaluation.
To see this in more detail, consider the postfix expression 4 5 6 * +. As you scan
the expression from left to right, you first encounter the operands 4 and 5. At this point,
you are still unsure what to do with them until you see the next symbol. Placing each on
the stack ensures that they are available if an operator comes next.
In this case, the next symbol is another operand. So, as before, push it and check
the next symbol. Now we see an operator, *. This means that the two most recent
operands need to be used in a multiplication operation. By popping the stack twice, we
can get the proper operands and then perform the multiplication (in this case getting the
result 30).
We can now handle this result by placing it back on the stack so that it can be used
as an operand for the later operators in the expression. When the final operator is
processed, there will be only one value left on the stack. Pop and return it as the result of
the expression. The next figure shows the stack contents as this entire example
expression is being processed.

Module 4 Stacks Page 17 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

The next figure below shows a slightly more complex example, 7 8 + 3 2 + /. There
are two things to note in this example. First, the stack size grows, shrinks, and then grows
again as the subexpressions are evaluated. Second, the division operation needs to be
handled carefully. Recall that the operands in the postfix expression are in their original
order since postfix changes only the placement of operators. When the operands for the
division are popped from the stack, they are reversed. Since division is not a commutative
operator, in other words 15/5 is not the same as 5/15, we must be sure that the order of
the operands is not switched.

Assume the postfix expression is a string of tokens delimited by spaces. The


operators are *, /, +, and - and the operands are assumed to be single-digit integer values.
The output will be an integer result.
 Algorithm
1. Create an empty stack called operandStack.
2. Iterate across the input using a for loop.
3. Scan the token vector from left to right.
• If the token is an operand, convert it from a string to an integer and push
the value onto the operandStack. (Using the ASCII, you can get this by
subtracting 48)
• If the token is an operator, *, /, +, or -, it will need two operands. Pop the
operandStack twice. The first pop is the second operand and the second
pop is the first operand. Perform the arithmetic operation. Push the result
back on the operandStack.
4. When the input expression has been completely processed, the result is on the
stack. Pop the operandStack and return the value.

The complete function for the evaluation of postfix expressions is shown in the following
C++ Implementation code. To assist with the arithmetic, a helper function doMath is
defined that will take two operands and an operator and then perform the proper
arithmetic operation.
 C++ Implementation
//Solves a postfix math problem.

#include <iostream>
#include <stack>
#include <string>

using namespace std;

int doMath(char op, int op1, int op2) {


//Does math based on what op is passed as.
if (op == '*') { return (op1 * op2); } else if
(op == '/') { return (op1 / op2); } else if
(op == '+') { return (op1 + op2);
} else {
return (op1 - op2);
}
}

int postfixEval(string postfixExpr) {


stack<int> operandStack;
string nums = "0123456789";

for (char i : postfixExpr) {


if ((nums.find(i) <= nums.length())) { // Check if the current char is a number
operandStack.push(int(i) - 48); // conversion from char to ascii // then
subtract 48 to get the int value
} else if (i != ' ') {
int operand2 = operandStack.top();
operandStack.pop();
int operand1 = operandStack.top();
operandStack.pop();
int result = doMath(i, operand1, operand2);
operandStack.push(result);
}

Module 4 Stacks Page 19 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

}
return operandStack.top();
}

int main() {
cout << "7 8 + 3 2 + /" << endl;
cout << postfixEval("7 8 + 3 2 + /") << endl;

return 0;
}

Self Check
Q-1: Without using the activecode infixToPostfix function, convert the following
expression to postfix 10 + 3 * 5 / (16 - 4).
Answer: ____________________________
Q-2: What is the result of evaluating the following: 17 10 + 3 * 9 / ? Answer:
==
____________________________

5. Teaching and Learning Activities


Consider the following pseudocode that uses a stack.
declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
1. What is the output for input "geeksquiz", using above pseudocode?
2. Create a C++ program that implements stack data structure to find all elements in
a given unsorted array that are greater than all elements present to their right.

For example:

Input: { 10, 4, 6, 3, 5 }

Output: 10, 6, 5 (The elements greater than all elements to its right)
6. Recommended learning materials and resources for supplementary reading.

References:
E. B. Costa, A. M. Toda, M. A. A. Mesquita and J. D. Brancher, "DSLEP (Data Structure
Learning Platform to Aid in Higher Education IT Courses)," Journal of Social, Behavioral,
Educational, Economic, Business and Industrial Engineering, vol. 8, no. 4, pp. 1143-1148,
2014.
YoYo Games Ltd., "DS Stacks," YoYo Games Ltd., 2018.
https://docs.yoyogames.com
/index.html?page=source%2Fdadiospice%2F002_reference%2Fdata%20structures%2F
in dex.html. [Accessed 30 April 2019].

https://runestone.academy/runestone/books/published/cppds/LinearBasic/Implementing
aStackCpp.html
https://runestone.academy/runestone/books/published/cppds/LinearBasic/InfixPrefixand
PostfixExpressions.html https://www.techiedelight.com/Category/stack/

7. Flexible Teaching Learning Modality (FTLM) adopted


Example:
Online (synchronous)
//Edmodo, google classroom, moodle, schoology, Podcast etc..
Remote (asynchronous)

//module, case study, exercises, problems sets, etc…


8. Assessment Task
1. Write a C++ program to implement stack data structure with push and pop
operation.
2. Create a C++ program that implements stack data structure to convert an Infix
arithmetic expression to Prefix arithmetic expression.
3. Create a C++ program that evaluates Prefix arithmetic expression.
9. References Online:
 https://runestone.academy/runestone/books/published/cppds/index.html
 https://www.studytonight.com/data-structures/stack-data-structure
 https://www.techiedelight.com/Category/stack/

Module 4 Stacks Page 21 of 22


By: Rowell F. Santiago
Isabela State University, Jones Campus
IT 211 Data Structure and Algorithms

YoYo Games Ltd., "DS Stacks," YoYo Games Ltd., 2018.


https://docs.yoyogames.com/index.html?page=source%2Fdadiospice%2F002_re
fer ence%2Fdata%20structures%2Findex.html. [Accessed 30 April 2019].

Books:
B. Costa, A. M. Toda, M. A. A. Mesquita and J. D. Brancher, "DSLEP (Data
Structure Learning Platform to Aid in Higher Education IT Courses)," Journal of
Social, Behavioral, Educational, Economic, Business and Industrial Engineering,
vol. 8, no. 4, pp. 1143-1148, 2014.

Prepared by:
Rowell F. Santiago
Assistant Professor 1
ISU Jones Campus

You might also like