Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views12 pages

DSA Lab 2

The document discusses implementing a singly linked list in C including creating the list, inserting nodes, finding the length, searching by key, and deleting the last node. Code snippets and outputs are provided for creating the linked list structure and functions for insertion, length, search, and deletion.
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)
32 views12 pages

DSA Lab 2

The document discusses implementing a singly linked list in C including creating the list, inserting nodes, finding the length, searching by key, and deleting the last node. Code snippets and outputs are provided for creating the linked list structure and functions for insertion, length, search, and deletion.
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/ 12

Algorithms & Data Structures

CSC-112
Lab Report 02

Name Muhammad Sharjeel

Registration FA21-BEE-130
Number

Class BEE-6B

Instructor’s Name Dr. Ali Mustafa

Lab Assessment
Post Lab Total
In-Lab
Data Presentation Data Analysis Writing Style

1
Singly Linked List Implementation
Objectives:
• To understand how to create a singly linked list.
• To understand how to insert nodes at end / start of a singly linked list.
• Implement other linked list operations such as searching the list for key, find the length of
linked list etc.

In-Lab:

Task # 01:
Make a new project and add “main.c”, “employee.c”, and “employee.h” files to this project.
Compile and run the program. Use the function “int getlistlength (struct employee* emp)”
defined in “employee.c” to print the length of linked list. You will have to add an option in menu
so that the user may see the length of list anytime he wishes.

Code:

Figure 1: employee.h file

2
3
Figure 2: main.c file

4
5
6
Figure 3: employee.c file

Output:

7
8
Figure 4: Outputs for option 1, 2, 4, 5 and 8

Task # 02:
Write a function to implement “search by key” for the linked list. This function should be able to
search the database by “age” and index of age.

Code:

Figure 5: Function searchNodeByage

9
Output:

Figure 6: Output for option 6

Post-Lab:

Task # 01:
Write appropriate function to implement the delete function. This function should allow the user
to delete the last node in the list.

Code:

Figure 7: employee.h file

Figure 8: main.c file

10
Figure 9: employee.c file

Output:

11
Critical Analysis:
In this lab we have learned how to create single linked list. We have also learned how to search
key element in a node and how to add node at the end of list. Furthermore, we have created a
function which delete the last node in a single linked list and then print node data and single linked
list before and after deleting last node.

12

You might also like