Devanshu File C
Devanshu File C
Devanshu File C
CSIT124
if (arr[i]== element)
return i;
return -1;
int element;
scanf("%d",&element);
return 0;
Output:
1.(b) Write a program for Binary Search
Name: Devanshu Shrivastava Enrollment Number: A2345921026
Date of Compilation :
Code:
#include <stdio.h>
if (array[mid] == x)
return mid;
if (array[mid] < x)
low = mid + 1;
else
high = mid - 1;
return -1;
int main(void) {
int x;
if (result == -1){
printf("Not found");
else{
return 0;
Output:
2. Write a program for Bubble sort
Name: Devanshu Shrivastava Enrollment Number: A2345921026
Date of Compilation :
Code:
#include<stdio.h>
printf("%d", A[i]);
printf("\n");
if (A[j]>A[j+1])
A[j] = A[j+1];
A[j+1] = temp;
int main()
printArray (A,n);
bubblesort (A,n);
printArray (A,n);
return 0;
Output:
3. Write a program for Selection sort
Name: Devanshu Shrivastava Enrollment Number: A2345921026
Date of Compilation :
Code:
#include <stdio.h>
int i, j, small;
small = i;
small = j;
arr[small] = arr[i];
arr[i] = temp;
int i;
int main()
printArr(a, n);
selectionsort(a, n);
printArr(a, n);
return 0;
Output:
4.(a) – Write a program to Implement Queue using Array
Name: Devanshu Shrivastava Enrollment Number: A2345921026
Date of Compilation :
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 50
void enqueue();
void dequeue();
void show();
int queue_array[MAX];
int rear = - 1;
int front = - 1;
void main()
int choice;
while (1)
scanf("%d", &choice);
switch (choice)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 8:
exit(1);
default:
void enqueue()
int add_item;
if (rear == MAX - 1)
else
if (front == - 1)
front = 0;
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
void dequeue()
return ;
else
front = front + 1;
void show()
int i;
if (front == - 1)
else
printf("Queue is : \n");
printf("\n");
}
Output: