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

Fourth Semester Department of Electrical Engineering

This document contains details about Lab Assignment 9 on linked list operations for the course Data Structures & Algorithms at NFC Institute of Engineering & Fertilizer Research Faisalabad. It includes C code functions to insert a node at the beginning, middle, and end of a linked list, search for a node, delete a node, replace a node's data, and print the linked list. The lab helped the student learn how to implement various operations on linked lists and understand the algorithms used.

Uploaded by

Hafeez Ali
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)
42 views5 pages

Fourth Semester Department of Electrical Engineering

This document contains details about Lab Assignment 9 on linked list operations for the course Data Structures & Algorithms at NFC Institute of Engineering & Fertilizer Research Faisalabad. It includes C code functions to insert a node at the beginning, middle, and end of a linked list, search for a node, delete a node, replace a node's data, and print the linked list. The lab helped the student learn how to implement various operations on linked lists and understand the algorithms used.

Uploaded by

Hafeez Ali
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/ 5

NFC Institute of Engineering&Fertilizer

Research Faisalabad

Department of Electrical Engineering


Fourth Semester
Course Title:
Data Structure & Algorithms (EE-232)
Topic:
Lab Assignments
Submitted To:
Dr. Salman Arain
Submitted By:
Hafeez Ali
Roll.No:
18-ELE-43
Reg.#:
2018-UET-NFC-FD-ELECT-43
Lab.No.9
LINKED LIST OPERATIONS
Task#1
Write a function to insert in the beginning of linked list.
C Function:
void insert(struct node* head, new_data)
{
struct node *newNode;

newNode = malloc(sizeof(struct node));

newNode->data = new_data;
newNode->next = head;

head = newNode;
}

Task#2
Write a function to insert in the middle of linked list.
C Function:
void insert(struct node* head, new_data)
{
struct node *newNode;

newNode = malloc(sizeof(struct node));

newNode->data = new_data;

struct node *temp = head;


for(int i=2; i < position; i++) {
if(temp->next != NULL) {
temp = temp->next;
}
}
newNode->next = temp->next;

temp->next = newNode;
}

Task#3
Write a function to insert in the last of linked list.
C Function:
void insert(struct node* head, int new_data)
{
struct node *newNode;

newNode = malloc(sizeof(struct node));

newNode->data = new_data;
newNode->next = NULL;

struct node *temp = head;

while(temp->next != NULL){
temp = temp->next;
}
temp->next = newNode
}
Task#4
Write a function to search an element in linked list.
C Function:
bool search(struct Node* head, int x)
{
struct Node* current = head;

while (current != NULL) {


if (current->key == x) {
return true;
}
current = current->next;
}
return false;
}

Task#5
Write a function to delete an element in linked list.
C Function:
del (struct node *before_del)
{
struct node *temp;

temp = before_del->next;

before_del->next = temp->next;

free(temp);
}
Task#6
Write a function to replace an element in linked list.
C Function:
node *modifyNode(struct node* Node, int old, int new)
{
while (Node != NULL){
if(Node->key == old) {
Node->key = new;
}
Node = Node->next;
}
}

Task#7
Write a function to display linked list.
C Function:
void printList(struct Node *node)
{
while (node != NULL) {
printf(" %d ", node->data);

node = node->next;
}
}

Conclusion:
In this lab, I came to know the implementation of different operations on
linked list such as Insert, Delete, Search & Replace. I concluded the concept of algorithms
used in the linked list.

You might also like