Avani DS Final
Avani DS Final
Government of Gujarat
L. D. College of Engineering
LABORATORY MANUAL
Information Technology Department
Semester III
Year 2023-24
[Prajapati Avaniben Kanjibhai]
[ 220280116099]
L. D. College of Engineering
Ahmedabad -380015
Prajapati Avaniben Kanjibhai 220280116099
Government of Gujarat
L. D. College of Engineering
Technological University.
Date:
Government of Gujarat
L. D. College of Engineering
Initial of
Exp. Page
Title Date Course
No. No.
In-charge
1 Introduction to pointers. Call by Value and Call by reference.
2 Introduction to Dynamic Memory Allocation. DMA functions malloc(),
calloc(), free() etc.
3 Implement a program for stack that performs following operations
using array.
(a) PUSH (b) POP (c) PEEP (d) PEEK (e) CHANGE (f) Count (g) DISPLAY
4 Implement a program to convert infix notation to postfix notation
using stack.
5 Write a program to implement QUEUE using arrays that performs
following operations (a) (a) INSERT (b) DELETE (c) DISPLAY
6 Write a program to implement Circular Queue using arrays that
performs following operations. (a) INSERT (b) DELETE (c) DISPLAY
7 Write a menu driven program to implement following operations on
the singly linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Reverse the list
⚫ Count total number of nodes
8 Write a program to implement stack using linked list.
9 Write a program to implement queue using linked list.
Prajapati Avaniben Kannjibhai 220280116099
Government of Gujarat
L. D. College of Engineering
Initial of
Exp. Page
Title Date Course
No. No.
In-charge
10 Write a program to implement following operations on the doubly
linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Count total number of nodes
11 Write a program to implement following operations on the circular
linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Count total number of nodes
12 Write a program to implement Bubble Sort and Selection Sort.
13 Write a program to implement Insertion Sort and Quick Sort.
14 Write a program to implement Merge Sort.
15 Write a program to implement Linear Search and Binary Search.
16 Write a program which create binary search tree.
17 Implement recursive and non-recursive tree traversing methods
inorder, preorder and post-order traversal.
Prajapati Avaniben Kanjibhai 220280116099
Practical 5
Aim: Write a program to implement QUEUE using arrays that performs following operations (a) (a) INSERT (b)
DELETE (c) DISPLAY.
Ans :
#include <stdio.h>
#define MAX_SIZE 100
int queue[MAX_SIZE];
int front = -1, rear = -1;
void delete() {
if (front == -1 || front > rear) {
printf("Queue is empty. Cannot delete.\n");
} else {
printf("Deleted %d from the queue.\n", queue[front]);
front++;
}
}
void display() {
if (front == -1 || front > rear) {
printf("Queue is empty.\n");
} else {
printf("Queue elements: ");
for (int i = front; i <= rear; i++) {
printf("%d ", queue[i]);
}
printf("\n");
}
}
int main() {
int choice, data;
while (1) {
printf("\nQueue Operations:\n");
printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n");
Prajapati Avaniben Kanjibhai 220280116099
switch (choice) {
case 1:
printf("Enter the element to insert: ");
scanf("%d", &data);
insert(data);
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice. Try again.\n");
}
}
}
Outputs :
Prajapati Avaniben Kanjibhai 220280116099
Practical-6
Aim: Write a program to implement Circular Queue using arrays that performs following operations. (a) INSERT
(b) DELETE (c) DISPLAY
Ans:
#include <stdio.h>
#define MAX_SIZE 100
int queue[MAX_SIZE];
int front = -1, rear = -1;
void delete() {
if (front == -1) {
printf("Queue is empty. Cannot delete.\n");
} else {
printf("Deleted %d from the circular queue.\n", queue[front]);
if (front == rear) {
front = rear = -1;
} else if (front == MAX_SIZE - 1) {
front = 0;
} else {
front++;
}
}
}
void display() {
Prajapati Avaniben Kanjibhai 220280116099
if (front == -1) {
printf("Queue is empty.\n");
} else {
printf("Circular Queue elements: ");
if (front <= rear) {
for (int i = front; i <= rear; i++) {
printf("%d ", queue[i]);
}
} else {
for (int i = front; i < MAX_SIZE; i++) {
printf("%d ", queue[i]);
}
for (int i = 0; i <= rear; i++) {
printf("%d ", queue[i]);
}
}
printf("\n");
}
}
int main() {
int choice, data;
printf("\nCircular Queue Operations:\n");
printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n");
while (1) {
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to insert: ");
scanf("%d", &data);
insert(data);
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
return 0;
default:
Prajapati Avaniben Kanjibhai 220280116099
Output:
Prajapati Avaniben Kanjibhai 220280116099
Practical-7
Aim: Write a menu driven program to implement following operations on the singly linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Reverse the list
Count total number of nodes.
Ans :
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
}
printf("Node with data %d inserted at the end.\n", data);
}
head = head->next;
free(temp);
printf("Node deleted from the beginning.\n");
}
}
temp = temp->next;
}
return count;
}
int main() {
int choice, data, afterData, beforeData, searchData;
printf("\nSingly Linked List Operations:\n");
printf("1. Insert at Beginning\n2. Insert at End\n3. Insert After Specific Node\n");
printf("4. Insert Before Specific Node\n5. Delete from Beginning\n6. Delete from End\n");
printf("7. Delete Specific Node\n8. Search a Node\n9. List Traversal\n10. Reverse the List\n");
printf("11. Count Total Number of Nodes\n12. Exit\n");
while (1) {
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to insert at the beginning: ");
scanf("%d", &data);
insertAtBeginning(data);
break;
case 2:
printf("Enter the element to insert at the end: ");
scanf("%d", &data);
insertAtEnd(data);
break;
case 3:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node after which to insert: ");
scanf("%d", &afterData);
insertAfterNode(data, afterData);
break;
case 4:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node before which to insert: ");
scanf("%d", &beforeData);
insertBeforeNode(data, beforeData);
break;
case 5:
deleteFromBeginning();
break;
case 6:
deleteFromEnd();
break;
case 7:
printf("Enter the data of the node to delete: ");
scanf("%d", &data);
deleteNode(data);
Prajapati Avaniben Kanjibhai 220280116099
break;
case 8:
printf("Enter the data to search for: ");
scanf("%d", &searchData);
searchNode(searchData);
break;
case 9:
displayList();
break;
case 10:
reverseList();
break;
case 11:
printf("Total number of nodes: %d\n", countNodes());
break;
case 12:
exit(0);
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}
PRACTICAL-8
ANS:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int main() {
int choice, data;
while (1) {
printf("\nStack Operations:\n");
printf("1. Push\n2. Pop\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to push onto the stack: ");
scanf("%d", &data);
push(data);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}
OUTPUT :
Prajapati Avaniben Kanjibhai 220280116099
Practical-9
AIM: Write a program to implement queue using linked list.
ANS :
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void display() {
if (front == NULL) {
printf("Queue is empty.\n");
} else {
struct Node* temp = front;
printf("Queue elements: ");
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}
}
int main() {
int choice, data;
while (1) {
printf("\nQueue Operations:\n");
printf("1. Enqueue\n2. Dequeue\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to enqueue into the queue: ");
scanf("%d", &data);
enqueue(data);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}
Prajapati Avaniben Kanjibhai 220280116099
OUTPUT :
Prajapati Avaniben Kanjibhai 220280116099
Practical-10
AIM: Write a program to implement following operations on the doubly linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Count total number of nodes
ANS:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* prev;
struct Node* next;
};
newNode->prev = temp;
}
printf("Node with data %d inserted at the end.\n", data);
}
return;
}
struct Node* temp = head;
while (temp != NULL && temp->data != beforeData) {
temp = temp->next;
}
if (temp == NULL) {
printf("Node with data %d not found.\n", beforeData);
} else {
newNode->next = temp;
newNode->prev = temp->prev;
temp->prev->next = newNode;
temp->prev = newNode;
printf("Node with data %d inserted before the node with data %d.\n", data, beforeData);
}
}
if (temp == NULL) {
printf("Node with data %d not found.\n", dataToDelete);
} else {
if (temp->prev != NULL) {
temp->prev->next = temp->next;
} else {
head = temp->next;
}
if (temp->next != NULL) {
temp->next->prev = temp->prev;
}
free(temp);
printf("Node with data %d deleted.\n", dataToDelete);
}
}
}
return count;
}
int main() {
int choice, data, afterData, beforeData, searchData;
while (1) {
printf("\nDoubly Linked List Operations:\n");
printf("1. Insert at Beginning\n2. Insert at End\n3. Insert After Specific Node\n");
printf("4. Insert Before Specific Node\n5. Delete from Beginning\n6. Delete from End\n");
printf("7. Delete Specific Node\n8. Search a Node\n9. List Traversal\n10. Count Total Number of
Nodes\n11. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to insert at the beginning: ");
scanf("%d", &data);
insertAtBeginning(data);
break;
case 2:
printf("Enter the element to insert at the end: ");
scanf("%d", &data);
insertAtEnd(data);
break;
case 3:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node after which to insert: ");
scanf("%d", &afterData);
insertAfterNode(data, afterData);
break;
case 4:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node before which to insert: ");
scanf("%d", &beforeData);
insertBeforeNode(data, beforeData);
break;
case 5:
deleteFromBeginning();
Prajapati Avaniben Kanjibhai 220280116099
break;
case 6:
deleteFromEnd();
break;
case 7:
printf("Enter the data of the node to delete: ");
scanf("%d", &data);
deleteNode(data);
break;
case 8:
printf("Enter the data to search for: ");
scanf("%d", &searchData);
searchNode(searchData);
break;
case 9:
displayList();
break;
case 10:
printf("Total number of nodes: %d\n", countNodes());
break;
case 11:
return 0;
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}
Practical-11
AIM: Write a program to implement following operations on the circular linked list.
⚫ Insert a node
◦ At beginning of the list
◦ At end of the list
◦ After specific node
◦ Before specific node
⚫ Delete a node
◦ From begin of the list
◦ From end of the list
◦ Specific node
⚫ Searching a node
⚫ List traversal
⚫ Count total number of nodes
ANS:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
head = newNode;
}
printf("Node with data %d inserted at the beginning.\n", data);
}
prev = temp;
temp = temp->next;
}
if (temp->data != beforeData) {
printf("Node with data %d not found.\n", beforeData);
} else {
newNode->next = temp;
prev->next = newNode;
printf("Node with data %d inserted before the node with data %d.\n", data, beforeData);
}
}
} else {
struct Node* temp = head;
struct Node* prev = NULL;
while (temp->next != head) {
prev = temp;
temp = temp->next;
}
if (temp == head) {
head = NULL;
} else {
prev->next = head;
}
free(temp);
printf("Node deleted from the end.\n");
}
}
position++;
} while (temp != head);
printf("Node with data %d not found.\n", searchData);
}
int main() {
int choice, data, afterData, beforeData, searchData;
Prajapati Avaniben Kanjibhai 220280116099
while (1) {
printf("\nCircular Linked List Operations:\n");
printf("1. Insert at Beginning\n2. Insert at End\n3. Insert After Specific Node\n");
printf("4. Insert Before Specific Node\n5. Delete from Beginning\n6. Delete from End\n");
printf("7. Delete Specific Node\n8. Search a Node\n9. List Traversal\n10. Count Total Number of
Nodes\n11. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element to insert at the beginning: ");
scanf("%d", &data);
insertAtBeginning(data);
break;
case 2:
printf("Enter the element to insert at the end: ");
scanf("%d", &data);
insertAtEnd(data);
break;
case 3:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node after which to insert: ");
scanf("%d", &afterData);
insertAfterNode(data, afterData);
break;
case 4:
printf("Enter the element to insert: ");
scanf("%d", &data);
printf("Enter the data of the node before which to insert: ");
scanf("%d", &beforeData);
insertBeforeNode(data, beforeData);
break;
case 5:
deleteFromBeginning();
break;
case 6:
deleteFromEnd();
break;
case 7:
printf("Enter the data of the node to delete: ");
scanf("%d", &data);
deleteNode(data);
break;
case 8:
printf("Enter the data to search for: ");
scanf("%d", &searchData);
searchNode(searchData);
Prajapati Avaniben Kanjibhai 220280116099
break;
case 9:
displayList();
break;
case 10:
printf("Total number of nodes: %d\n", countNodes());
break;
case 11:
return 0;
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}