Docsity

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

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");