0% found this document useful (0 votes)
5 views5 pages

lab5

The lab report details the implementation of stack operations using C++ as part of a Data Structures Lab course. It outlines the objectives, procedures, and source code for performing Push, Pop, and Top operations, along with test results and discussions on challenges faced. The experiment successfully demonstrated stack functionality and efficient memory management.

Uploaded by

Tayebur Fahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

lab5

The lab report details the implementation of stack operations using C++ as part of a Data Structures Lab course. It outlines the objectives, procedures, and source code for performing Push, Pop, and Top operations, along with test results and discussions on challenges faced. The experiment successfully demonstrated stack functionality and efficient memory management.

Uploaded by

Tayebur Fahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Green University of Bangladesh

Department of Software Engineering (SWE)


Faculty of Sciences and Engineering
Semester: Spring, Year: 2025, B.Sc. in SWE (regular)

LAB REPORT NO-05


Course Title: Data Structures Lab
Course Code: SWE 108 Section: 242 D_2

Lab Experiment Name: Implementation of Stack Operations using C++

Student Details

Name ID
Md. Tayebur Rahman Fahim 242034017

Lab Date :
Submission Date : 09.03.2025
Course Teacher’s Name : Abrar Hasan

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
TITLE OF THE LAB EXPERIMENT:

Implementation of Stack Operations using C++

OBJECTIVES/AIM:

 To learn the concept of stack and its operations.


 To develop a program that performs Push, Pop, and Top operations
efficiently.
 To manage stack operations dynamically and prevent overflow/underflow
errors.
 To explore stack implementation in competitive programming scenarios.

PROCEDURE/ANALYSIS/DESIGN:

Pseudocode for Stack Implementation:

1. Insert Data into Stack (Push Operation):

Function push(stack, value): Increase


index by 1
Store value at stack[index]

2. Remove Data from Stack (Pop Operation):

Function pop(stack): If index


is -1:
Print "Stack is Empty" Return
Else:
Decrease index by 1

3. Get the Top Element of Stack:

Function top(stack): If index


is -1:
Print "Stack is Empty" Else:
Print stack[index]

IMPLEMENTATION:

Source Code:

#include<bits/stdc++.h> using
namespace std;

int index = -1;

void push(int arr[], int data)


{
index++;
arr[index] = data;
}

void pop(int arr[])


{
if(index == -1)
{
cout << "Stack is Empty" << endl;
}
else
{
index--;
}
}

void top(int arr[])


{
if(index == -1)
{
cout << "Stack is Empty" << endl;
}
else
{
cout << arr[index] << endl;
}
}

int main()
{
int arr[100]; push(arr,
20);
push(arr, 15);
push(arr, 50);
pop(arr);
push(arr, 60);

while(index != -1)
{
top(arr);
pop(arr);
}
}

TEST RESULT/OUTPUT:

Test Cases and Observations:

Test Case 1: Attempt to pop from an empty stack


Test Case 2: Pushing values into the stack

Run successfully

Test Case 3: Displaying top element

Test Case 4: Sequential pop operations

DISCUSSION:

 What went well?


The stack was implemented successfully, and all functions worked
correctly.
 Challenges faced:
o Preventing access to an empty stack was tricky.
o Implementing clear function names for better readability.
 Difficult parts:
o Ensuring the correct behavior of pop and top operations.
 What was learned?
o Understanding the stack data structure.
o Implementing push, pop, and top operations.
o Managing memory efficiently in stack operations.

CONCLUSION:

This experiment successfully implemented a Stack using C++ with operations


such as Push, Pop, and Top. The modified implementation ensures clear function
naming, better error handling, and structured testing to validate stack behavior.

You might also like