Professional Documents
Culture Documents
Research Faisalabad
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->data = new_data;
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->data = new_data;
newNode->next = NULL;
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;
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.