03 Program

  • Uploaded by: Class 12 A
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 03 Program as PDF for free.

More details

  • Words: 170
  • Pages: 2
Program #include #include void bubblesort(int array[], int size) { int temp, ctr=0; for (int i=0; i<size; i++) { for (int j=0; j<(size-1)-i; j++) { if (array[j]>array[j+1]) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } }

//Bubble Sort Function

//Comparing the Elements //Swapping Elements

cout<<"\n\nThe array after iteration "<<++ctr<<" is:\n"; for (int k=0; k<size; k++) //Printing each iteration { cout<<array[k]<<"\t"; } }

}

int binarysearch(int arr[], int size, int query) { int first, mid, last; first=0; last=size-1; while(first<=last) { mid=(first+last)/2; if (query = = arr[mid]) return mid; else if (query>arr[mid]) first=mid+1; else last=mid-1; } return -1; } void main() { clrscr(); int arr[50], item, n, index, query, res; cout<<"Enter the number of elements: "; cin>>n; cout<<"Enter the elements: "; for (int i=0; i>arr[i]; }

//Binary Search Function

bubblesort(arr, n);

//Calling bubblesort()

cout<<"\n\nThe sorted array is:\n"; for (i=0; i>query; res=binarysearch(arr, n, query);

//Calling binarysearch()

if (res == -1) cout<<"Element not found "; else cout<<"Element found at position "<

Related Documents

03 Program
November 2019 8
Program
May 2020 25
Program
October 2019 41
Program
June 2020 15

More Documents from ""

08 Output
November 2019 18
02 Program
November 2019 20
05 Program
November 2019 14
01 Program
November 2019 15
04 Program
November 2019 19
03 Program
November 2019 8