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

Dsu Program

Uploaded by

saee7390
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)
21 views5 pages

Dsu Program

Uploaded by

saee7390
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

Dsu program

a menu driven c program for insert and delete operations on linear and circular queue using array

#include <stdio.h>

// Function to perform Bubble Sort

void bubbleSort(int arr[], int n) {

int temp, i, j;

for (i = 0; i < n - 1; i++) {

for (j = 0; j < n - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

// Swap the elements

temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

// Function to perform Insertion Sort

void insertionSort(int arr[], int n) {

int i, key, j;

for (i = 1; i < n; i++) {

key = arr[i];

j = i - 1;

while (j >= 0 && arr[j] > key) {

arr[j + 1] = arr[j];

j = j - 1;

arr[j + 1] = key;
}

// Function to perform Selection Sort

void selectionSort(int arr[], int n) {

int i, j, minIndex, temp;

for (i = 0; i < n - 1; i++) {

minIndex = i;

for (j = i + 1; j < n; j++) {

if (arr[j] < arr[minIndex]) {

minIndex = j;

// Swap the minimum element with the first element

temp = arr[i];

arr[i] = arr[minIndex];

arr[minIndex] = temp;

int main() {

int choice, n;

printf("Enter the number of elements in the array: ");

scanf("%d", &n);

int arr[n];

printf("Enter %d elements:\n", n);

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);

}
printf("Menu:\n");

printf("1. Bubble Sort\n");

printf("2. Insertion Sort\n");

printf("3. Selection Sort\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

bubbleSort(arr, n);

break;

case 2:

insertionSort(arr, n);

break;

case 3:

selectionSort(arr, n);

break;

default:

printf("Invalid choice!\n");

return 1;

printf("Sorted array:\n");

for (int i = 0; i < n; i++) {

printf("%d ", arr[i]);

printf("\n");

return 0;

}
Output

Queue Operations:

1. Linear Enqueue

2. Linear Dequeue

3. Circular Enqueue

4. Circular Dequeue

5. Display Linear Queue

6. Display Circular Queue

7. Exit

Enter your choice: 3

Enter the element to insert into Circular Queue: 2

Inserted 2 into Circular Queue

Queue Operations:

1. Linear Enqueue

2. Linear Dequeue

3. Circular Enqueue

4. Circular Dequeue

5. Display Linear Queue

6. Display Circular Queue

7. Exit

Enter your choice: 3

Enter the element to insert into Circular Queue: 5

Inserted 5 into Circular Queue

Queue Operations:

1. Linear Enqueue

2. Linear Dequeue

3. Circular Enqueue

4. Circular Dequeue
5. Display Linear Queue

6. Display Circular Queue

7. Exit

Enter your choice: 6

Circular Queue elements: 2 5

Queue Operations:

1. Linear Enqueue

2. Linear Dequeue

3. Circular Enqueue

4. Circular Dequeue

5. Display Linear Queue

6. Display Circular Queue

7. Exit

Enter your choice:

Exiting the program.

You might also like