0% found this document useful (0 votes)
30 views4 pages

DS Lab Report 2

This lab report details the implementation of a basic list data structure in C++ as part of the Data Structures and Algorithm course. It covers key components, functions, and tasks related to arrays, two-dimensional arrays, and structures, emphasizing user-defined input for flexibility. The report concludes with reflections on the learning process and the resources used for assistance.

Uploaded by

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

DS Lab Report 2

This lab report details the implementation of a basic list data structure in C++ as part of the Data Structures and Algorithm course. It covers key components, functions, and tasks related to arrays, two-dimensional arrays, and structures, emphasizing user-defined input for flexibility. The report concludes with reflections on the learning process and the resources used for assistance.

Uploaded by

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

Lab Report # 02 Data Structures and Algorithm

NATIONAL UNIVERSITY OF MODERN LANGUAGES


LAB REPORT-02

❖ DEPARTMENT: Bachelor of Science in Computer Science (BSCS)


 STUDENT NAME: Iqra Asif
 ROLL NUMBER: RC-488
❖ SEMESTER NUMBER: 3RD (Morning)
❖ COURSE: Data Structures and Algorithm
❖ SUBMITTED TO: Mr. Ahmed
 SBMITTED BY: Iqra Asif

F-23 BSCS( Morning)-RC-488 1


Lab Report # 02 Data Structures and Algorithm

INTRODUCTION:-
The code you provided is a basic program for creating a list of items. It allows you to add,
remove, and view the items in the list. The list is stored in an array, which is like a container
for holding items.
The code includes functions like initialize, which sets up the list, traverse, which shows you
the items in the list, and getLength, which tells you how many items are in the list. It also has
functions for checking if the list is empty or full.
The code has placeholders for functions that allow you to add or remove items from the list at
different positions. These functions need to be filled in to make the list work completely.
Overall, this code provides a foundation for creating a list data structure in C++. You can
customize it by adding more functions and features to suit your specific needs.

Key Components
1. List Class: The List class encapsulates the list's data and operations.

2. Data Array: The data array stores the list's items.

3. Length Variable: The length variable tracks the current number of items in the list.
Functions
1. Constructor (List()
 - Initializes the list by setting length to 0.
2. isEmpty()
 Checks if the list is empty by comparing length to 0.
 - Returns true if empty, false otherwise.
3. isFull()
 - Checks if the list is full by comparing length to MAX_SIZE.
 - Returns true if full, false otherwise.
4. getLength()
 - Returns the current number of items in the list (length).
5. *traverse()*
- Displays all items in the list by iterating through the data array.
6. *add(item)*

- Adds an item to the end of the list if it's not full.


- Increments length.

7. *remove()*
Removes the last item from the list if it's not empty.
- Decrements length.

8. *insertAt(pos, item)*

F-23 BSCS( Morning)-RC-488 2


Lab Report # 02 Data Structures and Algorithm

- Inserts an item at a specific position (pos) if the list is not full.


- Shifts items to the right to make space for the new item.
- Increments length.

9. *deleteAt(pos)*

- Removes an item from a specific position (pos) if the list is not empty.
- Shifts items to the left to fill the gap.
- Decrements length.

10. *search(item)*

- Finds the position of an item in the list.


- Returns the position if found, -1 otherwise.

Task 1:
Download the .cpp file given to you as a sample file which contains already implemented
general operations of the list such as: a. Initialization of the list b. Traversal of the list c.
Finding the length of the list d. Resetting the list e. Checking if the list is empty f. Checking if
the list is full 2. Understand how the general operations are implemented and discuss if there
is any confusion.
Code :

Discussion and Conclusion:-


Task 1: Array Declaration and Initialization

F-23 BSCS( Morning)-RC-488 3


Lab Report # 02 Data Structures and Algorithm

I successfully completed Task 1, which focused on declaring and initializing arrays in C++. I
chose to use user-defined input for flexibility, drawing from my previous experience with a
more static approach. While both methods are valid, this dynamic approach allowed me to
experiment and reinforce my understanding of array concepts.

Task 2: Two-Dimensional Arrays

Task 2 introduced me to two-dimensional arrays. I again opted for user-defined input to


maintain consistency. I employed nested loops to efficiently manipulate and print the array
elements. While a single loop can be used for sequential population, I found the nested
approach more intuitive for this specific task.

Task 3: Finding the Largest Element in a 2D Array

Task 3 required me to identify the largest element within a 2D array and its corresponding
row and column. I directly declared the array size and values, simplifying the problem.
Although a nested loop within a single variable can be used, I preferred my approach for its
clarity and ease of understanding.

Task 4: Functions in C++

Task 4 focused on functions in C++. I created four distinct functions as specified in the
scenario. While combining the getLength and getWidth functions into a single function
could have reduced function calls, I adhered to the given requirements. However, I also
experimented with this combined approach to broaden my understanding.

Task 5 and 6: Structures in C++

Tasks 5 and 6 explored structures in C++. In Task 5, I created a structure to represent student
data and used user-defined input to populate the fields. Task 6 extended this concept by pre-
assigning student names and marks. Both tasks provided valuable practice in working with
structures and their applications.

Overall, I have effectively reinforced my understanding of arrays, two-dimensional arrays,


functions, and structures through these tasks. By experimenting with different approaches and
considering alternative methods, I have gained a deeper appreciation for the versatility and
power of C++ programming.

Credit:-
 Gemini (google.com)
I have used this website to get help in my code.

F-23 BSCS( Morning)-RC-488 4

You might also like