Bubble Sort and Linear Search, Cheat Sheet of Data Structures and Algorithms

The document consists of pseudocode for Bubble Sort and Linear Search in C language.

Typology: Cheat Sheet

2021/2022

Uploaded on 11/27/2023

ashmita-sharma
ashmita-sharma 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BUBBLE SORT
Source Code(c):
#include <stdio.h>
void main() {
int n , i,arr[50],j,temp;
printf("Enter the no of the elements:");
scanf("%d",&n);
printf("Enter %d elements of array\n",n);
for ( i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
for ( i = 0;i < n; i++){
for ( j = 0; j < n-i-1;j++){
if(arr[j]>arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
pf3
pf4

Partial preview of the text

Download Bubble Sort and Linear Search and more Cheat Sheet Data Structures and Algorithms in PDF only on Docsity!

BUBBLE SORT

Source Code(c): #include <stdio.h> void main() { int n , i,arr[50],j,temp; printf("Enter the no of the elements:"); scanf("%d",&n); printf("Enter %d elements of array\n",n); for ( i = 0; i < n; i++){ scanf("%d",&arr[i]); } for ( i = 0;i < n; i++){ for ( j = 0; j < n-i-1;j++){ if(arr[j]>arr[j+1]){ temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp;

for ( i = 0;i < n;i++){ printf("%d ",arr[i]); }

if (i == n) printf("Element not found");