05 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 05 Program as PDF for free.

More details

  • Words: 173
  • Pages: 2
//Program 5 #include #include void SelectionSort(int ar[],int size) { int i, j; int small, tmp;

}

//Selection sort function

for (i=0; i<size; i++) { small = i; for (j=i+1; j<size; j++) { if (ar[small]>ar[j]) { small = j; } } tmp = ar[i]; ar[i] = ar[small]; ar[small] = tmp; }

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

SelectionSort(arr, n);

//Calling SelectionSort()

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

05 Program
November 2019 14
Program
May 2020 25
Program
October 2019 41
Program
June 2020 15
Program
July 2020 18

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