sachin
sachin
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct emp {
char name[30];
int age;
double salary;
};
int main() {
int n, i;
struct emp *employees;
printf("\nEmployee Records:\n");
for (i = 0; i< n; i++) {
printf("Employee %d:\n", i + 1);
printf("Name: %s\n", employees[i].name);
printf("Age: %d\n", employees[i].age);
printf("Salary: %.2lf\n", employees[i].salary);
}
free(employees);
return 0;
}
OUTPUT:
Enter the number of employees: 2
Enter details for employee 1:
Name:sachin
Age: 25
Salary: 163000
Enter details for employee
2: Name: priyanshu
Age: 25
Salary: 170000
Employee Records:
Employee 1:
Name:sachin
Age: 25
Salary: 163000.00
Employee 2:
Name: priyanshu
Age: 25
Salary: 170000.00
PROGRAM NO 2
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE:12-11-24
PROGRAM:
#include <stdio.h>
void inputArray(int arr[], int *n) {
printf("Enter size of array: ");
scanf("%d", n);
for (int i = 0; i< *n; i++) {
printf("Enter element %d: ", i + 1);
scanf("%d", &arr[i]);
}
}
void outputArray(int arr[], int n) {
for (int i = 0; i< n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
void insertElement(int arr[], int *n) {
int pos, ele;
printf("Enter position to insert: ");
scanf("%d", &pos);
printf("Enter element to insert: ");
scanf("%d", &ele);
for (int i = *n; i>pos - 1; i--) {
}
}
int main() {
int arr[100], n = 0,
choice; while (1) {
printf("\nMenu:\n1. Input Array\n2. Output Array\n3. Insert Element\n4. Delete
Element\n5. Sort Ascending\n6. Sort Descending\n7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: inputArray(arr, &n); break;
case 2: outputArray(arr, n); break;
case 3: insertElement(arr, &n); break;
case 4: deleteElement(arr, &n); break;
case 5: sortAscending(arr, n); break;
case 6: sortDescending(arr, n); break;
case 7: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice: 1
Enter size of array:
3 Enter element 1:
1
Enter element 2: 2
Enter element 3:
3 Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice:
2123
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice:
21243
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice: 4
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice: 5
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice:
2134
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice: 6
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
7. Exit
Enter your choice:
2431
PROGRAM NO 3
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE:12-11-24
Objective: Write a program to first sort the elements stored in two arrays in ascending
order and then merge them into a third array [without taking global variables].
PROGRAM:
#include <stdio.h>
void sortArray(int arr[], int n)
{ for (int i = 0; i< n - 1; i++) {
for (int j = 0; j < n - i - 1; j++)
{ if (arr[j] >arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void mergeArrays(int arr1[], int n1, int arr2[], int n2, int merged[]) {
int i = 0, j = 0, k = 0;
while (i< n1 && j < n2) {
if (arr1[i] < arr2[j]) {
merged[k++] = arr1[i++];
} else {
merged[k++] = arr2[j++];
}
}
while (i< n1) {
merged[k++] = arr1[i++];
}
while (j < n2) {
merged[k++] = arr2[j++];
}
}
int main() {
int n1, n2;
printf("Enter size of first array: ");
scanf("%d", &n1);
int arr1[n1];
printf("Enter elements of first array:\n");
for (int i = 0; i< n1; i++) {
scanf("%d", &arr1[i]);
}
OUTPUT:
Enter elements of first
array: 1
2
3
4
6
Enter size of second array: 3
Enter elements of second
array: 5
7
8
Merged and sorted
array: 1 2 3 4 5 6 7 8
PROGRAM NO 4
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE:12-11-24
Objective: Write a menu driven program of a stack using array having the push, pop and
display operations[without taking global variables].
PROGRAM:
#include <stdio.h>
#define MAX 100
void push(int stack[], int *top) {
int value;
if (*top == MAX - 1) {
printf("Stack Overflow\n");
return;
}
printf("Enter value to push: ");
scanf("%d", &value); stack[++
(*top)] = value;
}
int main() {
int stack[MAX], top = -1, choice;
while (1) {
printf("\nMenu:\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: push(stack, &top);
break; case 2: pop(stack, &top);
break;
case 3: display(stack, top); break;
case 4: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
3
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
2
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
1
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
3 Stack elements:
123
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
2 Popped value: 1
Menu:
1. Push
2. Pop
3. Display
4. Exit
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
2 Popped value: 2
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 3
Stack elements:
3
PROGRAM NO 5
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE:12-11-24
Objective: Write a menu driven program of a queue using array having add, delete and
display operations [without taking global variables].
PROGRAM:
#include <stdio.h>
#define MAX 100
int main() {
int queue[MAX], front = -1, rear = -1, choice;
while (1) {
printf("\nMenu:\n1. Add\n2. Delete\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: add(queue, &front, &rear); break;
case 2: delete(queue, &front, &rear); break;
case 3: display(queue, front, rear); break;
case 4: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 10
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 20
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice:
2 Deleted value: 10
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 30
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 40
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice:
3 Queue elements:
40 30 20
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice:
2 Deleted value: 40
PROGRAM NO 6
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
Objective: Write a menu driven program of a circular queue using array having add,
delete and display operations [without taking global variables].
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
void add(int queue[], int *front, int *rear, int value) {
if ((*front == 0 && *rear == MAX - 1) || (*rear == (*front - 1) % (MAX - 1)))
{ printf("Queue is full. Cannot add %d.\n", value);
return;
}
if (*front == -1) {
*front = *rear = 0;
} else if (*rear == MAX - 1 && *front != 0) {
*rear = 0;
} else {
(*rear)++;
}
queue[*rear] = value;
printf("Added %d to the queue.\n", value);
}
void delete(int queue[], int *front, int *rear) {
if (*front == -1) {
printf("Queue is empty. Cannot delete.\n");
return;
}
printf("Deleted %d from the queue.\n", queue[*front]);
if (*front == *rear) {
*front = *rear = -1;
}
printf("\n");
}
int main() {
do {
printf("\nMenu:\n");
printf("1. Add\n");
printf("2. Delete\n");
printf("3. Display\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter value to add: ");
scanf("%d", &value);
add(queue, &front, &rear,
value); break;
case 2:
delete(queue, &front,
&rear); break;
case 3:
display(queue, front,
rear); break;
case 4:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
return 0;
}
OUTPUT:
Menu:
1. Add
2. Delete
3. Display
4. Exit
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 63
Added 63 to the queue.
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 60
Added 60 to the queue.
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 3
Queue elements: 40 63 60
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 2
Deleted 40 from the queue.
PROGRAM NO 7
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE:12-11-24
Objective: Write a menu driven program of a stack using linked list having the push, pop
and display operations[without taking global variables].
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
void push(struct Node **top) {
int value;
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
if (!newNode) {
printf("Memory allocation failed\n");
return;
}
printf("Enter value to push: ");
scanf("%d", &value);
newNode->data =
value; newNode->next =
*top;
*top = newNode;
}
void pop(struct Node **top) {
if (*top == NULL) {
printf("Stack Underflow\n");
return;
}
struct Node *temp = *top;
printf("Popped value: %d\n", temp->data);
*top = (*top)->next;
free(temp);
}
int main() {
struct Node *top = NULL;
int choice;
while (1) {
printf("\nMenu:\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: push(&top); break;
case 2: pop(&top); break;
case 3: display(top);
break; case 4: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
10
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
20
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice: 1
Enter value to push:
30
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
3 Stack elements:
30 20 10
Menu:
1. Push
2. Pop
3. Display
4. Exit
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
2 Popped value: 20
Menu:
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:
3 Stack elements:
10
PROGRAM NO 8
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
Objective: Write a menu driven program of a queue using linked list having add, delete
and display operations [without taking global variables].
PROGRAM:
#include <stdio.h>
#include
<stdlib.h> struct
Node {
int data;
struct Node *next;
};
void add(struct Node **front, struct Node **rear) {
int value;
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
if (!newNode) {
printf("Memory allocation failed\n");
return;
}
printf("Enter value to add: ");
scanf("%d", &value);
newNode->data =
value; newNode->next =
NULL; if (*rear == NULL)
{
*front = *rear = newNode;
} else {
(*rear)->next = newNode;
*rear = newNode;
}
}
*front = (*front)-
>next; if (*front ==
NULL) {
*rear = NULL;
}
free(temp);
return;
}
printf("Queue elements:\n");
struct Node *temp = front;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
int main() {
struct Node *front = NULL, *rear = NULL;
int choice;
while (1) {
printf("\nMenu:\n1. Add\n2. Delete\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: add(&front, &rear); break;
case 2: delete(&front, &rear);
break; case 3: display(front); break;
case 4: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add:
46
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 47
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter value to add: 23
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice:
3 Queue elements:
46 47 23
Menu:
1. Add
2. Delete
3. Display
4. Exit
Enter your choice:
2 Deleted value: 46
PROGRAM NO 9
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
Objective: Write a menu driven program of a circular linked list with functions: insertion
at the beginning, deletion at the end, insertion between two nodes, deletion of first node,
deletion of last node, deletion of a node whose position is given, deletion of any node and
display. *
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
prev->next = *head;
free(temp);
}
newNode->data = value;
struct Node *temp = *head;
while (i<pos - 1 && temp->next != *head) {
temp = temp->next;
i++;
}
if (temp->next == *head &&pos != 1) {
printf("Position out of range\n");
free(newNode);
return;
}
newNode->next = temp-
>next; temp->next =
newNode;
}
void deleteFirstNode(struct Node **head) {
if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node *temp = *head;
if (temp->next == *head) {
free(temp);
*head = NULL;
} else {
struct Node *last = *head;
while (last->next != *head)
{
last = last->next;
}
*head = (*head)->next;
last->next = *head;
free(temp);
}
}
if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node *temp = *head, *prev = NULL;
if (pos == 1) {
deleteFirstNode(head);
return;
}
while (i<pos&& temp->next != *head) {
prev = temp;
temp = temp->next;
i++;
}
if (temp->next == *head &&i<pos) {
printf("Position out of range\n");
return;
}
prev->next = temp-
>next; free(temp);
}
if (*head == NULL) {
printf("List is empty\n");
return;
}
int main() {
struct Node *head = NULL;
int choice;
while (1) { printf("\
nMenu:\n");
printf("1. Insert at the beginning\n");
printf("2. Delete at the end\n");
printf("3. Insert between two nodes\n");
printf("4. Delete first node\n");
printf("5. Delete last node\n");
printf("6. Delete node at given position\n");
printf("7. Delete any node\n");
printf("8. Display list\n");
printf("9. Exit\n");
printf("Enter your choice:
"); scanf("%d", &choice);
switch (choice) {
}
}
}
OUTPUT:
Menu:
Menu:
1. Insert at the beginning
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 1
Enter value to insert at the beginning: 30
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
Menu:
1. Insert at the beginning
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 8
Circular Linked List: 30
20
Menu:
Menu:
1. Insert at the beginning
Menu:
1. Insert at the beginning
2. Delete at the end
8. Display list
9. Exit
Enter your choice: 4
Menu:
Menu:
1. Insert at the beginning
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 6
Enter position to delete : 2
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
Menu:
1. Insert at the beginning
8. Display list
9. Exit
Enter your choice: 8
Circular Linked List:
69
PROGRAM NO 10
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
Objective: Write a menu driven program of a doubly linked list with functions: insertion
at the beginning, deletion at the end, insertion between two nodes, deletion of first node,
deletion of last node, deletion of a node whose position is given, deletion of any node and
display[without taking global variables].
PROGRAM:
#include <stdio.h>
#include
<stdlib.h> struct
Node {
int data;
struct Node *prev;
struct Node *next;
};
void insertAtBeginning(struct Node **head) {
int value;
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
if (!newNode) {
printf("Memory allocation failed\n");
return;
}
printf("Enter value to insert at the beginning: ");
scanf("%d", &value);
newNode->data =
value; newNode->prev
= NULL;
newNode->next = *head;
if (*head != NULL) {
(*head)->prev = newNode;
}
*head = newNode;
}
newNode->data = value;
struct Node *temp = *head;
while (i<pos - 1 && temp != NULL) {
temp = temp->next;
i++;
}
if (temp == NULL) {
printf("Position out of range\n");
free(newNode);
return;
}
newNode->next = temp-
>next; newNode->prev =
temp;
if (temp->next != NULL) {
temp->next->prev = newNode;
}
temp->next = newNode;
}
free(temp);
}
temp = temp->next;
}
temp->prev->next =
NULL; free(temp);
}
void deleteNodeAtPosition(struct Node **head) {
int pos, i = 1;
printf("Enter position to delete (1-based index): ");
scanf("%d", &pos);
if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node *temp = *head;
if (pos == 1) {
deleteFirstNode(head);
return;
}
while (i<pos&& temp != NULL) {
temp = temp->next;
i++;
}
if (temp == NULL) {
printf("Position out of range\n");
return;
}
if (temp->next != NULL) {
temp->next->prev = temp->prev;
}
if (temp->prev != NULL) {
temp->prev->next = temp->next;
}
free(temp);
}
if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node *temp = *head;
if (temp->data == value) {
deleteFirstNode(head);
return;
}
while (temp != NULL && temp->data != value) {
temp = temp->next;
}
if (temp == NULL) {
printf("Value not found in the list\n");
return;
}
if (temp->next != NULL) {
temp->next->prev = temp->prev;
}
if (temp->prev != NULL) {
temp->prev->next = temp->next;
}
free(temp);
}
int main() {
case 9: return 0;
default: printf("Invalid choice\n");
}
}
}
OUTPUT:
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 1
Enter value to insert at the beginning: 9
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
Menu:
1. Insert at the beginning
8. Display list
9. Exit
Enter your choice: 8
Doubly Linked List: 27 18
9
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
5. Delete last node
6. Delete node at given position
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 3
Enter value to insert:
36
Enter position to insert : 3
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
9. Exit
Enter your choice: 8
Doubly Linked List: 27 18 36
Menu:
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
9. Exit
Enter your choice: 8
Doubly Linked List: 27
18
Menu:
1. Insert at the beginning
2. Delete at the end
3. Insert between two nodes
4. Delete first node
Menu:
1. Insert at the beginning
} else {
struct Node* temp = *head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
temp = i->data;
i->data = j-
>data; j->data =
temp;
}
}
}
}
// Base cases
if (list1 == NULL) return list2;
if (list2 == NULL) return list1;
} else {
result = list2;
result->next = mergeSortedLists(list1, list2->next);
}
return result;
}
int main() {
struct Node* list1 = NULL;
struct Node* list2 = NULL;
return 0;
OUTPUT:
Enter values for the first linked list (enter -1 to stop):
Enter value: 20
Enter value: 30
Enter value: 10
Enter value: 40
Enter value: 63
Enter value: -1
Enter values for the second linked list (enter -1 to stop):
Enter value: 1
Enter value: 2
Enter value: 3
Enter value: 5
Enter value: 6
Enter value: -1
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
int priority;
struct Node *next;
};
}
prev->next = newNode;
newNode->next =
temp;
}
int main() {
struct Node *head = NULL;
int choice, value, priority;
serve(&head);
break;
case 3:
display(head);
break;
case 4:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}
OUTPUT:
Menu:
1. Insert
2. Serve
3. Display
4. Exit
Menu:
1. Insert
2. Serve
3. Display
4. Exit
Enter your choice: 1
Menu:
1. Insert
2. Serve
3. Display
4. Exit
Enter your choice: 1
Menu:
1. Insert
2. Serve
3. Display
4. Exit
Enter your choice: 3
Priority Queue: 55(1) 45(8) 35(10)
Menu:
1. Insert
2. Serve
3. Display
4. Exit
Enter your choice:
2 Served: 55
PROGRAM NO 13
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
int i = 0, j = 0, k = left;
while (i < n1 && j < n2)
{
if (leftArr[i] <= rightArr[j]) {
arr[k] = leftArr[i];
i++;
} else {
arr[k] = rightArr[j];
j++;
} k+
+;
}
printf("\n");
}
int main() {
int n;
int arr[n];
mergeSort(arr, 0, n - 1);
return 0;
}
OUTPUT:
Enter the number of elements: 4
Enter the elements:
23
57
11
96
Unsorted array:
23 57 11 96
Sorted array:
11 23 57 96
PROGRAM NO 14
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
return i + 1;
}
int main() {
int n;
printf("Enter number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter elements: ");
for (int i = 0; i< n; i++) {
scanf("%d", &arr[i]);
}
quickSort(arr, 0, n - 1);
printf("Sorted array:
"); display(arr, n);
return 0;
}
OUTPUT:
Enter number of elements: 6
Enter elements: 18
47
23
12
75
52
Sorted array: 12 18 23 47 52 75
PROGRAM NO 15
NAME: SACHIN SHARMA
COURSE: B.TECH CSE
SEMESTER: 3RD
ROLL NO: 63
DATE: 12-11-24
Objective: Write a program to implement a binary search tree with following operation:
insertion, deletion and display.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
return root;
}
return root;
}
return root;
}
int main() {
struct Node* root = NULL;
int choice, value;
while (1) {
printf("\nMenu:\n");
printf("1. Insert\n");
printf("2. Delete\n");
printf("3. Display (In-order traversal)\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter value to insert: ");
scanf("%d", &value);
root = insert(root,
value); break;
case 2:
printf("Enter value to delete: ");
scanf("%d", &value);
root = delete(root,
value); break;
case 3:
printf("BST (In-order traversal): ");
display(root);
printf("\n");
break;
case 4:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
OUTPUT:
Menu:
1. Insert
2. Delete
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit
Enter your choice: 1
Enter value to insert:
55
Menu:
1. Insert
2. Delete
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit
Enter your choice: 3
BST (In-order traversal): 55 76
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit
Enter your choice: 1
Enter value to insert:
99
Menu:
1. Insert
2. Delete
3. Display (In-order traversal)
4. Exit