SlideShare a Scribd company logo
1 of 1
Dated: feb/26/2015
Course Title: Data Structures
Lab # 2
Array Implementation of Stack
Task#1
Write a program to convert a decimal number into its binary form using stack implementation.(6 Points)
The Algorithm for transforming decimal number into its binary equivalent is as follows:
Step 1. Create a stack (using array)
Step 2. Enter a decimal number
Step 3. Iteration 1 (while number > 0)
digit = number %2
push digit into stack
if stack is full
Print an error
Stop the algorithm
 End if condition
divide the number by 2
Step 4. End iteration 1
Step 5. Iteration 2 (while stack is not empty)
 Pop digit from stack
 Print the digit
Step 6. End Iteration 2
Step 7. Stop program
Task#2
Write a program to find the middle element of the stack using array. (4 Points)

More Related Content

What's hot (10)

Java programlist (1)
Java programlist (1)Java programlist (1)
Java programlist (1)
 
Pa1 loops
Pa1 loopsPa1 loops
Pa1 loops
 
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data StructureStudy & Analysis of Complexities of Stack & Queue Operations in Data Structure
Study & Analysis of Complexities of Stack & Queue Operations in Data Structure
 
For next
For nextFor next
For next
 
Matlab Files
Matlab FilesMatlab Files
Matlab Files
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
 
Comp 122 lab 4 lab report and source code
Comp 122 lab 4 lab report and source codeComp 122 lab 4 lab report and source code
Comp 122 lab 4 lab report and source code
 
Course project solutions 2018
Course project solutions 2018Course project solutions 2018
Course project solutions 2018
 
Matlab
MatlabMatlab
Matlab
 
Searching
Searching Searching
Searching
 

Viewers also liked (14)

Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Stack and Heap
Stack and HeapStack and Heap
Stack and Heap
 
Stack and heap allocation
Stack and heap allocationStack and heap allocation
Stack and heap allocation
 
Stack & heap
Stack & heap Stack & heap
Stack & heap
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
Operating system
Operating system Operating system
Operating system
 
Abc deportes ficha
Abc deportes fichaAbc deportes ficha
Abc deportes ficha
 
Medio ambiente
Medio ambienteMedio ambiente
Medio ambiente
 
Question 3
Question 3Question 3
Question 3
 
LISTINO AIXAM
LISTINO AIXAMLISTINO AIXAM
LISTINO AIXAM
 
Présentation "Pluie de vers", Pierre Mauget
Présentation "Pluie de vers", Pierre MaugetPrésentation "Pluie de vers", Pierre Mauget
Présentation "Pluie de vers", Pierre Mauget
 
2015RESUMENEW
2015RESUMENEW2015RESUMENEW
2015RESUMENEW
 

electic mashinary fundamentals 5th edition Lab tasks stack

  • 1. Dated: feb/26/2015 Course Title: Data Structures Lab # 2 Array Implementation of Stack Task#1 Write a program to convert a decimal number into its binary form using stack implementation.(6 Points) The Algorithm for transforming decimal number into its binary equivalent is as follows: Step 1. Create a stack (using array) Step 2. Enter a decimal number Step 3. Iteration 1 (while number > 0) digit = number %2 push digit into stack if stack is full Print an error Stop the algorithm  End if condition divide the number by 2 Step 4. End iteration 1 Step 5. Iteration 2 (while stack is not empty)  Pop digit from stack  Print the digit Step 6. End Iteration 2 Step 7. Stop program Task#2 Write a program to find the middle element of the stack using array. (4 Points)