You are on page 1of 12

Ivantha Guruge

Data Structures
Data structures are ways in which data is arranged in a

computers memory or stored in hard disk.

Overview of Data Structures


Array
Ordered Array Stack

Queue
Linked list Binary Tree

Hash Table
Graphs

Stacks

Stacks
Stack is a data structure, which is a list of data elements, that

all insertions and deletions are made at one end. This is the TOP (Begin) of the Stack.
Elements are removed from a Stack in the reverse order of

that in which the elements were inserted into the Stack.


Insertions and Deletions are restricted from the Middle and at

the End of a Stack data structure.


A Stack is a data structure that the elements are inserted and

removed according to the Last-In-First-Out (LIFO) principle.

Stacks
When we add an item to a Stack, we say that we PUSH it into the stack and when we remove an item, we say that we POP it from the stack.

Restricts Access

The fields of a stack


stackArray size of stack Array top of stack

private double[]; private int maxSize; // (Length) private int top; // initially -1

Stack methods
stack (int s); // constructor
void push(double j); // put item on top of stack

double pop();
double peek();

// take item from top of stack


// peek at top of stack

bool isEmpty();
bool isFull();

// true if stack is empty


// true if stack is full

Examples:
Internet web browsers storing addresses of recently

visited sites. Text Editor function undo. In microprocessors

Uses of the stack


Converting a sequence of numeric characters to the equivalent integer. Reversing character strings Evaluating arithmetic expressions Most microprocessors use a stack-based architecture.

Constructor
public Stack(int s) // constructor { maxSize = s; stackArray = new double[maxSize]; top = -1; }

Thank you

You might also like