Professional Documents
Culture Documents
College of Engineering
Salahaddin University-Erbil
Academic Year 2019-2020
ABSTRUCT
In this report I am going to talk about one pf the data structures which is stack,
.first by giving you specific information and description of data structure
what is this term meaning, a simple explanation about it, giving it a definition in
general with its types in the introduction part of my report, along with this in the
introduction we will give you a general information about the our current subject
.which is stack
What is stack, explaining in a definition, what is its role in the programming of our
devices . What dose it affects on, how dose it helps us to handle our complex
problems, describing it which provides push and pop operations with usual
semantics also the working with the single stack and multiple stack and its
.application
What is the types of stack and focusing on each of its types, there basic operations,
.and when and where the single stack works as multiple if we take as an example
Explaining this and more by giving practically examples with C++ language,
.explaining it by coding and outputs and also by some pictures to explain it more
.And we are trying to present our report in a special order to be easy to get it
First an introduction to the subject then a background and review, method, design
.and outcomes, an at the end we are getting to a conclusion about our subject
CONTENTS
ABSTRACT 2
CONTENTS 3
INTRODUCTION 4-6
BACKGROUND 7-8
DESIGN 9-11
CONCLUSION 12
SOURCES 13
INTRODUCTION
the time and memory complexity of a Data Structure but not from a data type.
But in these report we are going to show the example and all over the
explanations with C++ language, and we chose this because that I came to
that, it will be more easier and understandable and also more clearly to
Data Structures include array, linked lists, stacks, binary trees, and hash
And now I am going to give a simple explanation of abstract data types and
what dose it means. The coming to our main topic, doing that to be more
undersatandable.
data structures based on how they are used and the behaviors they provide.
They do not specify how the data structure must be implemented but simply
Stack holds a collection of elements but different from the Array or List those
elements can only be manipulated from one end of the stack. This end is
.commonly known to be the top of the stack
Stack Representation
The following diagram depicts a stack and its operations −
pop() – Return the item at the top of the stack and then remove it. If
pop is called when stack is empty, it is in an underflow state.
Balancing of symbols
BACKGROUND
OF THE PRACTICAL WAY
stack<ITEMTYPE> mystack;
A stack is a generic data structure, which means that we can add to it any
type of item (ITEMTYPE). For our first example, we'll
use Node<ITEMTYPE> objects, as defined in the previous chapter. Let's start
by creating and printing a short list.
LinkedList<int> list;
list.push_front (3);
list.push_front (2);
list.push_front (1);
list.print ();
The output is (1, 2, 3). To put a Node object onto the stack, use
the push method (assuming Node* node):
mystack.push (*node);
The following loop traverses the list and pushes all the nodes onto the stack:
stack<Node> mystack;
for (Node* node = list.head; node != NULL; node = node->next) {
mystack.push (*node);
}
mystack.pop ();
while (!mystack.empty ()) {
cout << mystack.top().cargo << " ";
mystack.pop();
}
The output is 3 2 1. In other words, we just used a stack to print the elements
of a list backwards! Granted, it's not the standard format for printing a list,
but using a stack it was remarkably easy to do.
DESIGN
class Stack {
int top;
public:
int pop();
bool isEmpty();
};
else {
myStack[++top] = item;
cout<<item<<endl;
int Stack::pop()
{ if (top < 0) {
return 0; }
return item; } }
bool Stack::isEmpty()
stack.push(2);
stack.push(4);
stack.push(6);
while(!stack.isEmpty())
Output:
The Stack Push
In the output, we can see that the elements are pushed into the stack in one
order and are popped out of the stack in the reverse order. This exhibits the LIFO
(Last in, First out) approach for the stack.
For the above array implementation of the stack, we can conclude that this is
very easy to implement as there are no pointers involved. But at the same time,
the size of the stack is static and the stack cannot grow or shrink dynamically.
********************************************************************************************
********************************************************************************************
1. PUSH
2. POP
The logic which is used behind these operations are Last In First Out(LIFO).
LIFO is a method, which tells us that the thing which is PUSH last should be
POP first.
And we can say in general, stacks are useful for processing nested structures
or for functions which call other functions (or themselves). A nested structure
is one that can contain instances of itself embedded within itself.
REFERENCES
1-Data Structures and Algorithms Made Easy(BOOK)