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

CSC 382 Computer Lab 3

A stack is a linear data structure that follows the last-in, first-out (LIFO) principle, where elements can only be inserted and removed from one end called the top. Key operations on a stack include push to add an element, pop to remove an element, peek to access the top element, and functions to check if the stack is full or empty. Stacks have many applications including undo/redo functions, converting between mathematical notation types, and memory management in computers.

Uploaded by

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

CSC 382 Computer Lab 3

A stack is a linear data structure that follows the last-in, first-out (LIFO) principle, where elements can only be inserted and removed from one end called the top. Key operations on a stack include push to add an element, pop to remove an element, peek to access the top element, and functions to check if the stack is full or empty. Stacks have many applications including undo/redo functions, converting between mathematical notation types, and memory management in computers.

Uploaded by

Class wrapper
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data structure can be classified into complex and compound data structures.

Linear Data structure


1. Stack Data structures:
A stack data structure is commonly used in most preogrammiong languages and behaves
like a real worl stack.

It is an Abstract data type ADT and by ADT it means it is made up of primitive datatype
but operation and implementation is hidden from the user.

So we say that in Stack terminologies, insertion operation is called push while removal
operation is called pop.

Its also worthy to note that at any given time we can only access the top element of the
stack.

Stack can be implemented using an array or a linked list


When it is implemented using an array, A stack becomes a fixed stack.

LIFO - Last in first out


FILO - First in last out

Basic operations of a stack data structure


1. Push() : Used to insert into a stack
2. Pop() : Used to remove into a stack
3. Top() or Peek() : Used to determine the top of a stack
4. isFull() : Used to check if a stack is full
5. isEmpty() : used to check if a stack is empty
6. Size() : used to determine the size of a stack (number of elements in a stack)

Application area of stack DS


1. Conversion of Polish notation like the Infix, Prefix and the Postfix notation.
2. Forward and backward features in a web browser
3. Undo and redo features of most application programs
4. Reversing of strings
5. Also very efficient for memory management in modern day computers

Basic steps of a push operation


1. Check if the stack is full
2. If stack is full produce an error and exit
3. If stack is not full, increment top() to point to the next empty space
4. Add data element to the stack location where the Top is pointing.
5. Return success

Pseudocode for Push()


Begin
If stack is full
return Null

Endif
Else

Top = top+1

Stack[top] = data

End else
End procedure

Pseudocode for Pop()


1. Check if the stack is empty
2. If the stack is not
3. If the stack is not empty, acess the data element at the top
4. Decrease the value of the start top by -1

Assignment
Impelement

You might also like