Q.5 Write A Program of Bubble Sort
Q.5 Write A Program of Bubble Sort
#include <stdio.h>
*xp = *yp;
*yp = temp;
int i, j;
bool swapped;
swapped = false;
swap(&arr[j], &arr[j+1]);
swapped = true;
if (swapped == false)
break;
}
int i;
printf("n");
int main()
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
printArray(arr, n);
return 0;
}
Q.6 Write a program of Selection sort.
#include <iostream>
*xp = *yp;
*yp = temp;
int i, j, min_idx;
min_idx = i;
min_idx = j;
swap(&arr[min_idx], &arr[i]);
{
int i;
int main()
int n = sizeof(arr)/sizeof(arr[0]);
selectionSort(arr, n);
printArray(arr, n);
return 0;
}
Q.7 Write a program of merge sort.
#include<stdlib.h>
#include<stdio.h>
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
i = 0;
j = 0;
k = l;
arr[k] = L[i];
i++;
else
{
arr[k] = R[j];
j++;
k++;
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
if (l < r)
int m = l+(r-l)/2;
mergeSort(arr, l, m);
int i;
printf("\n");
int main()
printArray(arr, arr_size);
printArray(arr, arr_size);
return 0;
}
Q.8 Write a program of Insertion sort.
#include <iostream>
int i, key, j;
key = arr[i];
j = i - 1;
arr[j + 1] = arr[j];
j = j - 1;
arr[j + 1] = key;
int i;
int main()
insertionSort(arr, n);
printArray(arr, n);
return 0;
}
Q.9 Write a program of Quick sort.
#include<iostream>
int main ()
cin >> n;
max = arr[i];
min = arr[0];
min = arr[i];
return 0;
}
Q.10 Write a program of Stack implementation using array.
#include<iostream>
#include<stdlib.h>
#include<conio.h>
int main()
char ch='y';
while(ch=='y' || ch=='Y')
cin>>item;
if(res == -1)
getch();
exit(1);
cin>>ch;
return -3;
if(top == SIZE-1)
{ return -1; }
else
top++;
stack[top] = elem;
return 0;
cout<<stack[i]<<"\n";
}
Q.10 Write a program of Queue implementation using array.
#include <iostream>
#include <stdio.h>
struct Queue {
int* queue;
Queue(int c)
front = rear = 0;
capacity = c;
if (capacity == rear) {
printf("\nQueue is full\n");
return;
else {
queue[rear] = data;
rear++;
return;
}
void queueDequeue()
if (front == rear) {
printf("\nQueue is empty\n");
return;
else {
rear--;
return;
void queueDisplay()
int i;
if (front == rear) {
printf("\nQueue is Empty\n");
return;
}
return;
void queueFront()
if (front == rear) {
printf("\nQueue is Empty\n");
return;
return;
};
int main(void)
Queue q(4);
q.queueDisplay();
q.queueEnqueue(54);
q.queueEnqueue(11);
q.queueEnqueue(82);
q.queueEnqueue(94);
q.queueDisplay();
q.queueEnqueue(95);
q.queueDisplay();
q.queueDequeue();
q.queueDequeue();
printf("\n\nafter two node deletion\n\n");
q.queueDisplay();
q.queueFront();
return 0;
}
Q.10 Write a programm to find ith smallest and largest no..
#include<iostream>
int main ()
cin >> n;
max = arr[0];
max = arr[i];
min = arr[0];
return 0;